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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Invesco
Helper V
Helper V

DAX Measure Switch with Hasonevalue gives incorrect results

Hi Experts

 

I have the following DAX measure which is giving the incorrect results when used as a measure in standard table

 

However, if i added the measures for example measure 6. TargetCoverage% to a card visual the end result is correct.

 

My discount table is as follows:

Invesco_0-1704893078620.png

 

 

 

FieldActivity_Total = 
VAR metric =
    SELECTEDVALUE ( 'Map_Field_Activity'[Sort] )
RETURN
IF(HASONEVALUE('Map_Field_Activity'[Metrics]),
              SWITCH (
                metric
                ,1,FORMAT ( [ActiveReps], "#,#" )
                ,2,FORMAT ( [Vacancy%]+0, "0.0%" )
                ,3,[CallDayRep]  --FORMAT ( [CallDayRep], "#,#")
                ,4,FORMAT ( [EffectiveInteractions %], "0.0%" )
                ,5,FORMAT ( [HCPsInPlanCoverageProduct], "#,#" )
                ,6,FORMAT ( [TargetCoverage%], "0.0%" )
                ,7,FORMAT ( [F2FCalls], "#,#" )
                ,8,FORMAT ( [VisitFreq], "#,#.##" )
                ,9,FORMAT ( [%Call Product], "0.0%" )
                ,10,FORMAT ([%useOfADV], "0.0%" )
                ,11,FORMAT ( [Events], "#,#" )
                ,12,FORMAT ( [PartRP], "#,#" )
                ,BLANK()
              ))

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Invesco ,

 

I'm guessing you're trying to change the format via sort, but that doesn't seem right with your current expression. First you fetch the value, which is correct, then you determine if the slicer fetched the value, and finally you make a judgment on the fetched value. So you should first have sort as a separate dimension table, which you can see below:

vtianyichmsft_0-1704943321823.png

vtianyichmsft_1-1704943331933.png

So you can try:

 

DimSort = SUMMARIZE('Map_Field_Activity','Map_Field_Activity'[Sort])
FieldActivity_Total = 
VAR _select =
    SELECTEDVALUE ( 'DimSort'[Sort] )
RETURN
IF(HASONEVALUE('DimSort'[Sort]),
              SWITCH (
                _select
                ,1,FORMAT ( [ActiveReps], "#,#" )
                ,2,FORMAT ( [Vacancy%]+0, "0.0%" )
                ,3,[CallDayRep]  --FORMAT ( [CallDayRep], "#,#")
                ,4,FORMAT ( [EffectiveInteractions %], "0.0%" )
                ,5,FORMAT ( [HCPsInPlanCoverageProduct], "#,#" )
                ,6,FORMAT ( [TargetCoverage%], "0.0%" )
                ,7,FORMAT ( [F2FCalls], "#,#" )
                ,8,FORMAT ( [VisitFreq], "#,#.##" )
                ,9,FORMAT ( [%Call Product], "0.0%" )
                ,10,FORMAT ([%useOfADV], "0.0%" )
                ,11,FORMAT ( [Events], "#,#" )
                ,12,FORMAT ( [PartRP], "#,#" )
                ,BLANK()
              ))

 

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

2 REPLIES 2
Anonymous
Not applicable

Hi @Invesco ,

 

I'm guessing you're trying to change the format via sort, but that doesn't seem right with your current expression. First you fetch the value, which is correct, then you determine if the slicer fetched the value, and finally you make a judgment on the fetched value. So you should first have sort as a separate dimension table, which you can see below:

vtianyichmsft_0-1704943321823.png

vtianyichmsft_1-1704943331933.png

So you can try:

 

DimSort = SUMMARIZE('Map_Field_Activity','Map_Field_Activity'[Sort])
FieldActivity_Total = 
VAR _select =
    SELECTEDVALUE ( 'DimSort'[Sort] )
RETURN
IF(HASONEVALUE('DimSort'[Sort]),
              SWITCH (
                _select
                ,1,FORMAT ( [ActiveReps], "#,#" )
                ,2,FORMAT ( [Vacancy%]+0, "0.0%" )
                ,3,[CallDayRep]  --FORMAT ( [CallDayRep], "#,#")
                ,4,FORMAT ( [EffectiveInteractions %], "0.0%" )
                ,5,FORMAT ( [HCPsInPlanCoverageProduct], "#,#" )
                ,6,FORMAT ( [TargetCoverage%], "0.0%" )
                ,7,FORMAT ( [F2FCalls], "#,#" )
                ,8,FORMAT ( [VisitFreq], "#,#.##" )
                ,9,FORMAT ( [%Call Product], "0.0%" )
                ,10,FORMAT ([%useOfADV], "0.0%" )
                ,11,FORMAT ( [Events], "#,#" )
                ,12,FORMAT ( [PartRP], "#,#" )
                ,BLANK()
              ))

 

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

DataInsights
Super User
Super User

@Invesco,

 

Field parameters provide a more robust way of achieving this. One of the benefits is that you don't have to use the FORMAT function which converts the value to text. Instead, each measure's formatting is used.

 

https://learn.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters 





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

Proud to be a Super User!




Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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