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

Need Help on Dax

I have table  with below columns with like this

2018 Year-End Marker2019 Year-End Marker2020 Year-End Marker
HMMMMH
MMHMMM
HMMHHM
HMMMMM
MLLLLM
MMLHMM
MHHHMH


And I have date slicer with Years 2021, 2020 and 2019. I need to calculate If I select year 2021, I need to get the count of c(HH,HM,MH) in 2020 Yearend Marker and If I select year 2020, I need to get the count of c(HH,HM,MH) in 2019 Year end Marker.

I used this following expression and its not working.

Promotions =
IF(SELECTEDVALUE(Dim_Date, Dim_Date[Year] ="2021"), Calculate(COUNT(EmployeeMaster[2020 Year-End Marker]),
FILTER(EmployeeMaster, [2020 Year-End Marker] in {"HH","HM","MH"})),
IF(SELECTEDVALUE(Dim_Date[Year] ="2020"), Calculate(COUNT(EmployeeMaster[2019 Year-End Marker]),
FILTER(EmployeeMaster, [2020 Year-End Marker] in {"HH","HM","MH"})), "_"))

Please help
1 ACCEPTED SOLUTION
Tanushree_Kapse
Impactful Individual
Impactful Individual

Hi @Anonymous 

 

Use the below measure:

if(SELECTEDVALUE(Dim_Date[Year])="2021",CALCULATE(COUNT('Sample'[2020 Year-End Marker]), 'Sample'[2020 Year-End Marker] in {"HH","HM","MH"}),if(SELECTEDVALUE(Dim_Date[Year])="2020",CALCULATE(COUNT('Sample'[2020 Year-End Marker]), 'Sample'[2019 Year-End Marker] in {"HH","HM","MH"}),"_"))
 
and make sure that the Year Column has Text datatype.
 
 
Mark this as a solution, if I answered your question. Kudos are always appreciated.
Thanks

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @Anonymous 
Hear is the sample file with the solution https://www.dropbox.com/t/Iw44tUGijEnBmA1z
The best approach is to have your data arranged in a proper way. You need to unpivot your data into only two columns (one for the year and one for the year end marker). This is simple just follow below steps
1.png2.png3.png4.png5.png
Once the data is ready the rest is simple. First set your relationship as follows:
7.png6.png
Then write your measure 

Promotions = 
CALCULATE (
    COUNTROWS ( 
        FILTER ( 
            EmployeeMaster, 
            EmployeeMaster[Year-End Marker] IN { "HH", "HM", "MH" } 
        )
    ),
    Dim_Date[Year] = MAX ( Dim_Date[Year] ) - 1
)

finally build your report where you can slice by Dim_Date[Year]
9.png

Tanushree_Kapse
Impactful Individual
Impactful Individual

Hi @Anonymous 

 

Use the below measure:

if(SELECTEDVALUE(Dim_Date[Year])="2021",CALCULATE(COUNT('Sample'[2020 Year-End Marker]), 'Sample'[2020 Year-End Marker] in {"HH","HM","MH"}),if(SELECTEDVALUE(Dim_Date[Year])="2020",CALCULATE(COUNT('Sample'[2020 Year-End Marker]), 'Sample'[2019 Year-End Marker] in {"HH","HM","MH"}),"_"))
 
and make sure that the Year Column has Text datatype.
 
 
Mark this as a solution, if I answered your question. Kudos are always appreciated.
Thanks

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 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.