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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
ChavdarG
Frequent Visitor

Summation based on a measure

Dear all,

 

I already spent too much time on this, so hope you can help. Seems like a pretty basic thing to do but I cannot.

 

I have 2 slicers: Region and Country. The combination of the 2 selections, can give me the Zone.

I can call out the zone via a measure:

ZONE SELECTION = LOOKUPVALUE('ALL CCs'[Zone],'ALL CCs'[Country name],SELECTEDVALUE('ALL CCs'[Country name]),
'ALL CCs'[Region],SELECTEDVALUE('ALL CCs'[Region]))
 
Now I need to use the zone, which is returned here and sum up the column showing Gross Sales Revenue.
However, CALCULATE does not work with measures:
BP GSR 4 ZONE SELECTED = CALCULATE(SUM('ALL CCs'[GSR BP]),'ALL CCs'[Zone]=[ZONE SELECTION]))
 
"A function 'SELECTEDVALUE' has been used in a True/False expression that is used as a table filter
expression. This is not allowed."
 
What is a workaround to this?
 
Thank you,
Chavdar
1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi , @ChavdarG 

Are you referring to an error like the following?

42.png

If so ,it is suggested to  set a variable to store the value of the measure.

Please change you measure as below:

BP GSR 4 ZONE SELECTED = 
VAR a = [ZONE SELECTION]
RETURN
    CALCULATE ( SUM ( 'ALL CCs'[GSR BP] ), 'ALL CCs'[Zone] = a )

You can also use the filter function to encapsulate your filter expression:

BP GSR 4 ZONE SELECTED2 =
CALCULATE (
    SUM ( 'ALL CCs'[GSR BP] ),
    FILTER ( 'ALL CCs' , 'ALL CCs'[Zone] = [ZONE SELECTION] )
)

 

Best Regards,
Community Support Team _ Eason

View solution in original post

4 REPLIES 4
v-easonf-msft
Community Support
Community Support

Hi , @ChavdarG 

Are you referring to an error like the following?

42.png

If so ,it is suggested to  set a variable to store the value of the measure.

Please change you measure as below:

BP GSR 4 ZONE SELECTED = 
VAR a = [ZONE SELECTION]
RETURN
    CALCULATE ( SUM ( 'ALL CCs'[GSR BP] ), 'ALL CCs'[Zone] = a )

You can also use the filter function to encapsulate your filter expression:

BP GSR 4 ZONE SELECTED2 =
CALCULATE (
    SUM ( 'ALL CCs'[GSR BP] ),
    FILTER ( 'ALL CCs' , 'ALL CCs'[Zone] = [ZONE SELECTION] )
)

 

Best Regards,
Community Support Team _ Eason

Hello,

Yes, this is it. I knew I was missing something and it shouldn't be too complicated.

Thx a lot!

edhans
Super User
Super User

Try one of the following:

VAR varSelection =
    LOOKUPVALUE(
        'ALL CCs'[Zone],
        'ALL CCs'[Country name], SELECTEDVALUE( 'ALL CCs'[Country name] ),
        'ALL CCs'[Region], SELECTEDVALUE( 'ALL CCs'[Region] )
    )
RETURN
    CALCULATE(
        SUM( 'ALL CCs'[GSR BP] ),
        'ALL CCs'[Zone] = varSelection
    )

That still uses a predicate, which may be the issue, not that CALCULATE cannot work with measures. If that fails, try this:

Final Measure =
VAR varSelection =
    LOOKUPVALUE(
        'ALL CCs'[Zone],
        'ALL CCs'[Country name], SELECTEDVALUE( 'ALL CCs'[Country name] ),
        'ALL CCs'[Region], SELECTEDVALUE( 'ALL CCs'[Region] )
    )
RETURN
    CALCULATE(
        SUM( 'ALL CCs'[GSR BP] ),
        FILTER(
            ALL( 'ALL CCs'[Zone] ),
            'ALL CCs'[Zone] = varSelection
        )
    )

It replaces the predicate with the underlying code using FILTER.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
parry2k
Super User
Super User

@ChavdarG It will be easier if you share pbix file using one drive/google drive with the expected output. Remove any sensitive information before sharing.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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