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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors