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
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
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.