Categories
Uncategorized

Use Variables



Here is a sample measure from a client’s Power BI file
Confirmed =
CALCULATE (
    COUNTROWS ( ‘happyfit schedule’ ),
    ‘ happyfit  schedule'[is_accept] = TRUE,
    ‘ happyfit  schedule'[is_cancel] = FALSE,
    ‘ happyfit  schedule'[is_complete] = FALSE,
    ‘ happyfit  schedule'[is_decline] = FALSE,
    ‘ happyfit  schedule'[is_no_show] = FALSE,
    ‘ happyfit  schedule'[is_noresponse] = 0,
    ‘ happyfit  schedule'[province_id] = 1,
    DATESBETWEEN (
        ‘ happyfit  schedule'[date],
        DATE ( 2019, 06, 01 ),
        DATE ( 2019, 06, 30 )
    )
) + 0

There are lots of issues with this code, but we will start with adding a couple of variables.

Confirmed =
VAR month_start =
    DATE ( 2019, 06, 01 )
VAR month_end =
    DATE ( 2019, 06, 30 )
VAR row_count =
    CALCULATE (
        COUNTROWS ( ‘ happyfit  schedule’ ),
        ‘ happyfit  schedule'[is_accept] = TRUE,
        ‘ happyfit  schedule'[is_cancel] = FALSE,
        ‘ happyfit  schedule'[is_complete] = FALSE,
        ‘ happyfit  schedule'[is_decline] = FALSE,
        ‘ happyfit   schedule'[is_no_show] = FALSE,
        ‘ happyfit  schedule'[is_noresponse] = 0,
        ‘ happyfit  schedule'[province_id] = 1,
        DATESBETWEEN ( ‘ happyfit  schedule'[date], month_start, month_end )
    ) + 0
RETURN
    row_count