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
fabdata1207
Regular Visitor

Dynamic Total Column based on slicer

Hi Guys,

 

I have the challenge that I need to show the dynamic total in a separeted column according to a slicer.

 

For example if I filter 2 countries I need to show the total for these two countries. The reson is because I need this total to be a dynamic denominator for future calculations.

 

Please see the sample below:

 

Filter: Selected Australia and Singapore = total of 10 

 

CountryValueTotal Dynamic Colum
Australia510
New Zealand310
Singapore510
Total1310

 

Slicer: Selected New Zealand and Singapore = total of 8

 

CountryValueTotal Dynamic Colum
Australia58
New Zealand38
Singapore58
Total138

 

Is there anyway to achieve this with DAX?

 

Thanks!!

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

Hi @fabdata1207 ,

 

A calculated column is static, it won't change for slicer selection.

You may try a measure instead.

 

First you need to create a separate country table for the slicer to select. This country table cannot have a relationship with the main table.

A calculated table:

Country=DISTINCT('Table'[Country])

vstephenmsft_0-1647335623885.png

vstephenmsft_1-1647335631662.png

 

Then, create a measure.

Total Dynamic Measure = CALCULATE(SUM('Table'[Value]),FILTER(ALLSELECTED('Table'),[Country] in ALLSELECTED(Country[Country])))

vstephenmsft_3-1647335752981.png

vstephenmsft_4-1647335763645.png

 

You can check more details from the attachment.

 

 

Best Regards,

Stephen Tao

 

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

 

 

 

View solution in original post

2 REPLIES 2
v-stephen-msft
Community Support
Community Support

Hi @fabdata1207 ,

 

A calculated column is static, it won't change for slicer selection.

You may try a measure instead.

 

First you need to create a separate country table for the slicer to select. This country table cannot have a relationship with the main table.

A calculated table:

Country=DISTINCT('Table'[Country])

vstephenmsft_0-1647335623885.png

vstephenmsft_1-1647335631662.png

 

Then, create a measure.

Total Dynamic Measure = CALCULATE(SUM('Table'[Value]),FILTER(ALLSELECTED('Table'),[Country] in ALLSELECTED(Country[Country])))

vstephenmsft_3-1647335752981.png

vstephenmsft_4-1647335763645.png

 

You can check more details from the attachment.

 

 

Best Regards,

Stephen Tao

 

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

 

 

 

mahoneypat
Employee
Employee

Yes. Create a disconnected table with the values of interest with the DISTINCT or VALUES function, and use that new table/column in your slicer. You can then use an expression like this to get your dynamic total.

 

Selected Total =
VAR sel =
DISTINCT( SlicerTable[Country] )
RETURN
CALCULATE(
SUM( table[Value] ),
ALL( Table[Country] ),
Table[Country] IN sel
)

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.