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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply

DAX measure with filters and divisions

Hi there,

 

With the input below,

 

CategoryTypeYearValue
ZApple202150.00
ZApple2022150.00
AApple20212500.00
AApple20223000.00
AApple20234000.00
BApple20214250.00
BApple20225000.00
BApple20235500.00
CApple20215500.00
CApple20226000.00
CApple20236100.00
XApple20215000.00
XApple20226000.00
XApple20238000.00
ZOrange202150.00
ZOrange202250.00
AApple20212500.00
AApple20223000.00
AApple20233000.00
BApple20211000.00
BApple20221300.00
BApple20231850.00
CApple202112.50
CApple2022615.00
CApple20231617.50
XApple2021788.13
XApple2022945.75
XApple2023103.38

 

I need help converting data using a measure to convert

 

 202120222023
Z100200 
A500060007000
B525063007350
C5512.566157717.5
X5788.1256945.758103.375

 

 

to 

 202120222023
Z100200 
A503035
B52.531.536.75
C55.12533.07538.5875
X5788.1256945.758103.375

 

Is there a measure where I can write, that can help turn the table above to the table below? Rows A-C will need to be divided by row Z (100) for 2021, and for 2022 onwards, Rows A-C will need be divided by row Z (200)

 

= IF(
AND(OR('Table'[Category]="A",'Table'[Category]="B",'Table'[Category]="C"),'Table'[Year]="2021")
DIVIDE(
        SUM('Table'[Value]),
(CALCULATE(SUM('Table'[Value]),'Table'[Year]="2021",'Table'[Category]="Z")),
IF(OR('Table'[Category]="A",'Table'[Category]="B",'Table'[Category]="C")),
DIVIDE(
        SUM('Table'[Value]),
(CALCULATE(SUM('Table'[Value]),'Table'[Year]="2022",'Table'[Category]="Z")),
Table'[Value])
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @analyticspbi87 ,

Based on my testing, please try the following methods:

1.Create the simple table.

vjiewumsft_0-1712729669914.png

2.Create the new measure to calculate per year.

 

total per year = CALCULATE(SUM('Table'[Value]), ALLEXCEPT('Table','Table'[Category],'Table'[Year]))

 

vjiewumsft_4-1712729894075.png

 

3.Create the new measure to convert table.

 

convert = 
VAR z_2021 = CALCULATE(SUM('Table'[Value]), FILTER('Table', 'Table'[Category] = "Z" && 'Table'[Year] = 2021))
VAR z_2022 = CALCULATE(SUM('Table'[Value]), FILTER('Table', 'Table'[Category] = "Z" && 'Table'[Year] = 2022))
VAR year_ = SELECTEDVALUE('Table'[Year])
VAR CATE = SELECTEDVALUE('Table'[Category])
RETURN
IF(CATE IN {"A", "B", "C"} && year_ = 2021, DIVIDE([total per year], 100), IF(CATE IN {"A", "B", "C"} && year_ in {2022, 2023}, DIVIDE([total per year], 200), [total per year])
)

 

4.Drag the measure into the matrix visual.

vjiewumsft_1-1712729791418.png

5.The result is shown below.

vjiewumsft_2-1712729798077.png

 

Best Regards,

Wisdom Wu

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

1 REPLY 1
Anonymous
Not applicable

Hi @analyticspbi87 ,

Based on my testing, please try the following methods:

1.Create the simple table.

vjiewumsft_0-1712729669914.png

2.Create the new measure to calculate per year.

 

total per year = CALCULATE(SUM('Table'[Value]), ALLEXCEPT('Table','Table'[Category],'Table'[Year]))

 

vjiewumsft_4-1712729894075.png

 

3.Create the new measure to convert table.

 

convert = 
VAR z_2021 = CALCULATE(SUM('Table'[Value]), FILTER('Table', 'Table'[Category] = "Z" && 'Table'[Year] = 2021))
VAR z_2022 = CALCULATE(SUM('Table'[Value]), FILTER('Table', 'Table'[Category] = "Z" && 'Table'[Year] = 2022))
VAR year_ = SELECTEDVALUE('Table'[Year])
VAR CATE = SELECTEDVALUE('Table'[Category])
RETURN
IF(CATE IN {"A", "B", "C"} && year_ = 2021, DIVIDE([total per year], 100), IF(CATE IN {"A", "B", "C"} && year_ in {2022, 2023}, DIVIDE([total per year], 200), [total per year])
)

 

4.Drag the measure into the matrix visual.

vjiewumsft_1-1712729791418.png

5.The result is shown below.

vjiewumsft_2-1712729798077.png

 

Best Regards,

Wisdom Wu

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

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.