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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
MDR
Frequent Visitor

Conditional SUM

I used the following DAX to return total "Approved" amounts across all datanameshorts in my dfact table. When datanameshort is either "SBG" or "SBG10" the total of "Approved" and "Paid" amounts must be returned instead.

As datanameshort is a column I needed to use selectedvalue to get a single value out of all values in the column and looks like that makes the condition to be always False (only else part gets executed)

ApprovedAmount =
IF (
CONTAINSSTRING(SELECTEDVALUE(DFACT[DATANAMESHORT]), "SBG"), CALCULATE(SUM(DFACT[AMOUNT]), FILTER(DFACT, CONTAINSSTRING(DFACT[DATANAMESHORT],"SBG") && DFACT[STATUS] IN {"Approved","Paid"} && DFACT[GEONAME] <> BLANK())),
CALCULATE(SUM(DFACT[AMOUNT]), FILTER(DFACT, DFACT[STATUS] = "Approved")))

 

Does anyone have any idea how to fix this.

a screenshot of the dfact table is added 

SBG_ApprovedPaid.png 

1 ACCEPTED SOLUTION

The problem is that there is more than value for data name short, so SELECTEDVALUE will return blank.

Try

ApprovedAmount =
IF (
    NOT ISEMPTY ( INTERSECT ( VALUES ( DFACT[DATANAMESHORT] ), { "SBG", "SBG10" } ) ),
    CALCULATE (
        SUM ( DFACT[AMOUNT] ),
        DFACT[DATANAMESHORT]
            IN { "SBG", "SBG10" }
                && DFACT[STATUS]
                    IN { "Approved", "Paid" } && NOT ISBLANK ( DFACT[GEONAME] )
    ),
    CALCULATE ( SUM ( DFACT[AMOUNT] ), DFACT[STATUS] = "Approved" )
)

View solution in original post

4 REPLIES 4
johnt75
Super User
Super User

How are you using the measure? Is it in a visual which includes the data name short column or is it just in aggregation ?

MDR
Frequent Visitor

I have it in a table with datname as below:

MDR_1-1680520642813.png

 

Small Business Disaster Recovery Grants represents both "SBG" and "SBG10".

I've used a similar aggregated measure in a card without any issues but in the table instead of getting the sum of "Approved" and "Paid" for "Small Business Disaster Recovery Grants" I am getting only "Approved".

The aggregated mesure is as follows:

CALCULATE(SUM(DFACT[AMOUNT]), FILTER(DFACT, CONTAINSSTRING(DFACT[DATANAMESHORT],"SBG") && DFACT[STATUS] IN {"Approved", "Paid"} && DFACT[GEONAME] <> BLANK())

The problem is that there is more than value for data name short, so SELECTEDVALUE will return blank.

Try

ApprovedAmount =
IF (
    NOT ISEMPTY ( INTERSECT ( VALUES ( DFACT[DATANAMESHORT] ), { "SBG", "SBG10" } ) ),
    CALCULATE (
        SUM ( DFACT[AMOUNT] ),
        DFACT[DATANAMESHORT]
            IN { "SBG", "SBG10" }
                && DFACT[STATUS]
                    IN { "Approved", "Paid" } && NOT ISBLANK ( DFACT[GEONAME] )
    ),
    CALCULATE ( SUM ( DFACT[AMOUNT] ), DFACT[STATUS] = "Approved" )
)
MDR
Frequent Visitor

Thanks heaps @johnt75. it worked

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors