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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Dynamic DAX Division by Category and Slicer

I am trying to build a dynamic measure with a toggle as below:  Its is likely simple for pros, but can't seem to figure out the DAX way.
See PBIX attached - https://ufile.io/n4nji186 
Current measure: 

 

 

 

sum Dynamic = 
VAR toggle =
    SELECTEDVALUE ( 'Select Div'[Val],0 )

return( CALCULATE(
            DIVIDE(SUM('Table'[sale]), 0.5)
)
)

 

 

 


Required measure:

if toggle = Divide: 
when category in A, C - divide sum(sale) by 1 (in other words don't divide, just keep the numerator as is)
when category = B = divide sum(sale) by 0.5


If toggle = No_Divide : 
Do nothing and calculate the sum(sale) without any division.  



Thanks in advance!

Andy

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous ,

As a new measure

new measure =
Switch( True() ,
max(Table[category]) in {"A","C"} , sum(sale)/1,
max(Table[category]) in {"B"} , sum(sale)/0.5,
sum(sale))

 

As a new colum
new column =
Switch( True() ,
(Table[category]) in {"A","C"} , (sale)/1,
(Table[category]) in {"B"} , (sale)/0.5,
(sale))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous ,

As a new measure

new measure =
Switch( True() ,
max(Table[category]) in {"A","C"} , sum(sale)/1,
max(Table[category]) in {"B"} , sum(sale)/0.5,
sum(sale))

 

As a new colum
new column =
Switch( True() ,
(Table[category]) in {"A","C"} , (sale)/1,
(Table[category]) in {"B"} , (sale)/0.5,
(sale))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello I would like to make a dynamic division of the average daily sales, I have a summary table by the days of each month. But I need you to change the division of the total amount of sales by the number of days of the month. For example 1

Total sales September = 100

Days of the month of September = 30

Result 100/30

example 2

Total sales October = 100

Days of the month of September = 31

result 100/31

Thank you.

Anonymous
Not applicable

Thanks for the help! This worked partially. The problem is that the individual category calculation changes correct, but the total of all categories (matrix) is not adjusted. How can we get the category change to be retained in the Total  Any other ideas?

Sum Dynamic =
VAR toggle = SELECTEDVALUE('Select Div'[Val])

return (
Switch( True() ,
max('Table'[category]) in {"A","C"} && toggle = "Divide", sum('Table'[sale]),
max('Table'[category]) in {"B"} && toggle = "No_Divide", sum('Table'[sale])/0.5,
sum('Table'[sale])
)
)
Anonymous
Not applicable

Hi @Anonymous 

 

IF(('Table'[toggle] = "Divide" && 'Table'[category] in {"A","C"}) || 'Table'[toggle] = "No_Divide", SUM('Table'[sale]), 

           IF('Table'[toggle] = "Divide" && 'Table'[category] = "B", DIVIDE(SUM('Table'[sale]), 0.5),0

          )

  )

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors