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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Change Measure formula based on filter condition

 

How do I write a DAX measure based on a condition on 'TYPE' column? If TYPE = P, then count distinct employee IDs times .33 else just diplay count distinct employees. This measure will be used on a layout that will not have the 'TYPE' column in it. 

 

TYPEEMP COUNT DISTINCTDESIRED - EMP COUNT DISTINCT
F200200
P5016.50
2 ACCEPTED SOLUTIONS
Arul
Super User
Super User

@Anonymous ,

try this

 

Emp count distinct = 
VAR _disctinctCount = DISTINCTCOUNT('Sample Table'[employeeID])
VAR _result = IF(SELECTEDVALUE('Sample Table'[Type]) = "P",_disctinctCount*0.33,_disctinctCount)
RETURN _result

 

Thanks,

Arul





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


View solution in original post

Anonymous
Not applicable

Hello @Arul  and the forum!

 

When the 'Type' column is not being used on the layout. The measure is not doing the math. Therefore, I resolved the issue with the dax code below.

Active FTEs (Cal_2) =
VAR _P =
    CALCULATE (
        DISTINCTCOUNT ( EMP_TRAN_FACT[HR Employee ID] ),
        EMP_TRAN_FACT[HR Employee Event Type] = "ACTIVE"
            && EMP_TRAN_FACT[HR Employee Job Type] = "P"
    )
VAR _F =
    CALCULATE (
        DISTINCTCOUNT ( EMP_TRAN_FACT[HR Employee ID] ),
        EMP_TRAN_FACT[HR Employee Event Type] = "ACTIVE"
            && EMP_TRAN_FACT[HR Employee Job Type] = "F"
    )
RETURN
    CALCULATE (
        SUMX (
            VALUES ( EMP_TRAN_FACT[HR Employee Job Type] ),
            IF ( EMP_TRAN_FACT[HR Employee Job Type] = "P", _P * 0.33, _F )
        )
    )

 

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hello @Arul  and the forum!

 

When the 'Type' column is not being used on the layout. The measure is not doing the math. Therefore, I resolved the issue with the dax code below.

Active FTEs (Cal_2) =
VAR _P =
    CALCULATE (
        DISTINCTCOUNT ( EMP_TRAN_FACT[HR Employee ID] ),
        EMP_TRAN_FACT[HR Employee Event Type] = "ACTIVE"
            && EMP_TRAN_FACT[HR Employee Job Type] = "P"
    )
VAR _F =
    CALCULATE (
        DISTINCTCOUNT ( EMP_TRAN_FACT[HR Employee ID] ),
        EMP_TRAN_FACT[HR Employee Event Type] = "ACTIVE"
            && EMP_TRAN_FACT[HR Employee Job Type] = "F"
    )
RETURN
    CALCULATE (
        SUMX (
            VALUES ( EMP_TRAN_FACT[HR Employee Job Type] ),
            IF ( EMP_TRAN_FACT[HR Employee Job Type] = "P", _P * 0.33, _F )
        )
    )

 

 

Arul
Super User
Super User

@Anonymous ,

try this

 

Emp count distinct = 
VAR _disctinctCount = DISTINCTCOUNT('Sample Table'[employeeID])
VAR _result = IF(SELECTEDVALUE('Sample Table'[Type]) = "P",_disctinctCount*0.33,_disctinctCount)
RETURN _result

 

Thanks,

Arul





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Anonymous
Not applicable

Thanks a lot @Arul . Works perfectly! Learnt something new today 🙂

I just had to tweak the first variable to filter the data. 

 

VAR _disctinctCount = CALCULATE(DISTINCTCOUNT('Sample Table'[employeeID]), 'Sample Table'[Column] in {"abc", "xyz"})

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.