Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
sabilahmed
Resolver I
Resolver I

Number of sessions and days incorrect sum and total - Needs to be dynamic per period

In the below matrix, I am trying to display the number of sessions and number of doctor days per clinic location. But the sum and totals are wrong (the below visual is for the period of 2021 and 2022 (2 years worth of data)):

 

sabilahmed_0-1663084035037.png

The DAX for Doctor days is simple: No. of sessions / 2

 

The trouble is the No of sessions is giving me the wrong figures. See below DAX:

 

No of Sessions = 
 VAR _encounters =
    Calculate(DISTINCTCOUNT('Transaction Attributes'[Encounter Number__EBM__Encounter Number]),Filter ('Transaction Attributes', 'Base Measures'[Charges]>0))
 
 RETURN
    SWITCH (
        TRUE (),
        _encounters <= 2, 0,
        _encounters >= 2
            && _encounters <= 10, 1,
        _encounters > 10, 2
    )

 

[Charges] is a very simple measure:

 

Charges = 
            CALCULATE (
                [Amount],
                FILTER (
                    ALL ( 'Profitability Account' ),
                    'Profitability Account'[Description] = "Charges"
                )
            )

 

What could I be doing wrong? The measure works for 1 day per location but when I look at extended period of times like 1 week/ 1 month or 1 year it doesnt total the value of No. of sessions properly.

 

Please help! If you need any more information from or screenshots let me know.

 

Also this is a Direct Query from a Data Cube (Analysis Services). Not Import. 

 

1 ACCEPTED SOLUTION
sabilahmed
Resolver I
Resolver I

Solved!

No of Sessions = 
 VAR _encounters =
    CALCULATE (
        [Amount],
        FILTER (
            ALL ( 'Profitability Account' ),
            'Profitability Account'[Description] = "Encounters"
        )
    )
 VAR _NoOfDays = Calculate(DISTINCTCOUNT('Time'[CalendarDate]),Filter ('Time', 'Time'[DayOfWeekdayDescription] <> "Sunday" && 'Time'[DayOfWeekdayDescription] <> "Saturday"  ))
 VAR _NoOfSession = _NoOfDays * SWITCH (
        TRUE (),
        _encounters <= 2, 0,
        _encounters >= 2
            && _encounters <= 10, 1,
        _encounters > 10, 2
    )
 RETURN _NoOfSession

 

View solution in original post

2 REPLIES 2
sabilahmed
Resolver I
Resolver I

Solved!

No of Sessions = 
 VAR _encounters =
    CALCULATE (
        [Amount],
        FILTER (
            ALL ( 'Profitability Account' ),
            'Profitability Account'[Description] = "Encounters"
        )
    )
 VAR _NoOfDays = Calculate(DISTINCTCOUNT('Time'[CalendarDate]),Filter ('Time', 'Time'[DayOfWeekdayDescription] <> "Sunday" && 'Time'[DayOfWeekdayDescription] <> "Saturday"  ))
 VAR _NoOfSession = _NoOfDays * SWITCH (
        TRUE (),
        _encounters <= 2, 0,
        _encounters >= 2
            && _encounters <= 10, 1,
        _encounters > 10, 2
    )
 RETURN _NoOfSession

 

v-zhangti
Community Support
Community Support

Hi, @sabilahmed 

 

Is the condition of the SWITCH function coincident?

No of Sessions = 
 VAR _encounters =
    Calculate(DISTINCTCOUNT('Transaction Attributes'[Encounter Number__EBM__Encounter Number]),Filter ('Transaction Attributes', 'Base Measures'[Charges]>0))
 
 RETURN
    SWITCH (
        TRUE (),
        _encounters < 2, 0,
        _encounters >= 2
            && _encounters <= 10, 1,
        _encounters > 10, 2
    )

If you don't solve your problem, can you tell me the desired result, which can be reflected in the screenshot.

 

Best Regards,

Community Support Team _Charlotte

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

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.