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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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
v-tianyich-msft
Community Support
Community Support

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
v-tianyich-msft
Community Support
Community Support

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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