Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Switch and calculate

Hi everyone,   I am trying to calculate percentage total no of transactions occured across filters.   My data is as follows, Hour Weekname Count_loading_col Total_loading Total teus Loca...
  • v-alq-msft's avatar
    6 years ago

    Hi, Anonymous 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

     

    Table:

     

    You may create a measure as below.

    Percenatage = 
    var _table = ALLSELECTED('Table')
    var tab = 
    SUMMARIZE(
        'Table',
        'Table'[Weekname],
        "Result",
        var _weekname = [Weekname]
        var newtab = 
        SUMMARIZE(
            _table,
            'Table'[Hour],
            'Table'[Weekname],
            'Table'[Location_name],
            "flag",
            IF(
                'Table'[Hour]>4&&[Location_name]<>"",
                1,0
            )
        )
        return
        DIVIDE(
            CALCULATE(
                DISTINCTCOUNT('Table'[Location_name]),
                FILTER(
                      newtab,
                      'Table'[Weekname]=_weekname&&
                      [flag]=1
                )
            ),
            COUNTROWS(
                FILTER(
                    newtab,
                    [Weekname]=_weekname&&
                    [Location_name]<>""
                )
            )
        )
    )
    return
    SUMX(
        tab,
        [Result]
    )

     

    The overall count for '20WK25' with a location is 10. The distinct count location name with criteria of hour>4 for '20WK25' is 5. Here is the result.

     

    If I misunderstand your thoughts, please show us your expected result. 

     

    Best Regards

    Allan

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.