Reply
keckraguilar
Frequent Visitor
Partially syndicated - Outbound

Measure is creating duplicate rows in a table

I am trying to sum charges for the two previous months. The grand total is right but the grand total is duplicating down every row. Below are the two DAX formulas I am using. I think the issue is with the "ALL" being in the formula but I can't figure it out. I also included a screenshot of the fields in my table. 

 

 

Total Charges Current Month =
  VAR __MaxMonth = MAXX( ALL( 'Volume Files' ), 'Volume Files'[Month Number] )
  VAR __Result = CALCULATE(SUM('Volume Files'[Total Charges]), FILTER( ALL( 'Volume Files' ), [Month Number] = __MaxMonth), FILTER( ALL( 'Volume Files' ), 'Volume Files'[Discharge Date - Fiscal Year]="FY2024" ))
RETURN
  __Result

 

 

 

Total Charges Previous Month =
  VAR __MaxMonth = MAXX( All( 'Volume Files' ), 'Volume Files'[Month Number] )
  VAR __Result = CALCULATE(SUM('Volume Files'[Total Charges]), FILTER( ALL( 'Volume Files' ), [Month Number] = __MaxMonth - 1 ), FILTER( All( 'Volume Files' ), 'Volume Files'[Discharge Date - Fiscal Year]="FY2024" ))
RETURN
  __Result

 

keckraguilar_0-1725636863723.png

keckraguilar_1-1725636998743.png

 

1 ACCEPTED SOLUTION
v-kaiyue-msft
Community Support
Community Support

Syndicated - Outbound

Hi @keckraguilar ,

 

You can change your expression to something like this.

Total Charges Current Month = 
VAR __CurrentPatient =
    SELECTEDVALUE ( 'Volume Files'[Patient Encounter - Service Line 2] )
VAR __MaxMonth =
    MAXX ( ALL ( 'Volume Files' ), 'Volume Files'[Month Number] )
VAR __Result =
    CALCULATE (
        SUM ( 'Volume Files'[Total Charges] ),
        FILTER (
            ALL ( 'Volume Files' ),
            [Month Number] = __MaxMonth
                && 'Volume Files'[Discharge Date - Fiscal Year] = "FY2024"
                && 'Volume Files'[Patient Encounter - Service Line 2] = __CurrentPatient
        )
    )
VAR __total =
    CALCULATE (
        SUM ( 'Volume Files'[Total Charges] ),
        FILTER (
            ALLSELECTED ( 'Volume Files' ),
            [Month Number] = __MaxMonth
                && 'Volume Files'[Discharge Date - Fiscal Year] = "FY2024"
        )
    )
RETURN
    IF (
        ISINSCOPE ( 'Volume Files'[Patient Encounter - Service Line 2] ),
        __Result,
        __total
    )

 

Total Charges Previous Month = 
VAR __CurrentPatient =
    SELECTEDVALUE ( 'Volume Files'[Patient Encounter - Service Line 2] )
VAR __MaxMonth =
    MAXX ( ALL ( 'Volume Files' ), 'Volume Files'[Month Number] )
VAR __Result =
    CALCULATE (
        SUM ( 'Volume Files'[Total Charges] ),
        FILTER (
            ALL ( 'Volume Files' ),
            [Month Number] = __MaxMonth - 1
                && 'Volume Files'[Discharge Date - Fiscal Year] = "FY2024"
                && 'Volume Files'[Patient Encounter - Service Line 2] = __CurrentPatient
        )
    )
VAR __total =
    CALCULATE (
        SUM ( 'Volume Files'[Total Charges] ),
        FILTER (
            ALLSELECTED ( 'Volume Files' ),
            [Month Number] = __MaxMonth - 1
                && 'Volume Files'[Discharge Date - Fiscal Year] = "FY2024"
        )
    )
RETURN
    IF (
        ISINSCOPE ( 'Volume Files'[Patient Encounter - Service Line 2] ),
        __Result,
        __total
    )

 

vkaiyuemsft_0-1725849412026.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

View solution in original post

3 REPLIES 3
v-kaiyue-msft
Community Support
Community Support

Syndicated - Outbound

Hi @keckraguilar ,

 

You can change your expression to something like this.

Total Charges Current Month = 
VAR __CurrentPatient =
    SELECTEDVALUE ( 'Volume Files'[Patient Encounter - Service Line 2] )
VAR __MaxMonth =
    MAXX ( ALL ( 'Volume Files' ), 'Volume Files'[Month Number] )
VAR __Result =
    CALCULATE (
        SUM ( 'Volume Files'[Total Charges] ),
        FILTER (
            ALL ( 'Volume Files' ),
            [Month Number] = __MaxMonth
                && 'Volume Files'[Discharge Date - Fiscal Year] = "FY2024"
                && 'Volume Files'[Patient Encounter - Service Line 2] = __CurrentPatient
        )
    )
VAR __total =
    CALCULATE (
        SUM ( 'Volume Files'[Total Charges] ),
        FILTER (
            ALLSELECTED ( 'Volume Files' ),
            [Month Number] = __MaxMonth
                && 'Volume Files'[Discharge Date - Fiscal Year] = "FY2024"
        )
    )
RETURN
    IF (
        ISINSCOPE ( 'Volume Files'[Patient Encounter - Service Line 2] ),
        __Result,
        __total
    )

 

Total Charges Previous Month = 
VAR __CurrentPatient =
    SELECTEDVALUE ( 'Volume Files'[Patient Encounter - Service Line 2] )
VAR __MaxMonth =
    MAXX ( ALL ( 'Volume Files' ), 'Volume Files'[Month Number] )
VAR __Result =
    CALCULATE (
        SUM ( 'Volume Files'[Total Charges] ),
        FILTER (
            ALL ( 'Volume Files' ),
            [Month Number] = __MaxMonth - 1
                && 'Volume Files'[Discharge Date - Fiscal Year] = "FY2024"
                && 'Volume Files'[Patient Encounter - Service Line 2] = __CurrentPatient
        )
    )
VAR __total =
    CALCULATE (
        SUM ( 'Volume Files'[Total Charges] ),
        FILTER (
            ALLSELECTED ( 'Volume Files' ),
            [Month Number] = __MaxMonth - 1
                && 'Volume Files'[Discharge Date - Fiscal Year] = "FY2024"
        )
    )
RETURN
    IF (
        ISINSCOPE ( 'Volume Files'[Patient Encounter - Service Line 2] ),
        __Result,
        __total
    )

 

vkaiyuemsft_0-1725849412026.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

audreygerred
Super User
Super User

Syndicated - Outbound

You can create one measure for your charges as Total Charges = SUM( 'Volume Files'[Total Charges] ), then create a second measure for prior month like Total Charges Previous Month = CALCULATE ([Total Charges], PREVIOUSMONTH ('DateTable', [Date]). Then, when you filter to the year and month your [Total Charges] measure will show that amount and [Total Charges Previous Month] will return the prior month. 

PREVIOUSMONTH function (DAX) - DAX | Microsoft Learn





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Syndicated - Outbound

I am trying to make the formula dynamic and not have to manually change the date field every month when data refreshes

avatar user

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)