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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors