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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Measures Format

I created two measures

 

HE = SUM('Table'[Extra Hours] )

 

% HE = DIVIDE( [HE]; [Total Hours]; BLANK() )

 

Where HE is the sum of "Extra Hours" and %HE is Extra Hours / Total Hours

 

For the second one, I changed the format to % (if I put it on a visual, it works perfectly)

 

Than, I wanted to put both measures in the same visual and switch from one the another with a botton, putting this third measure in the visual:

 

HE or %HE = SWITCH(TRUE();

                                    [Case] = 1; [HE];

                                    [Case] = 2; [% HE];

                                    BLANK()

                                    )

 

This new measure works perfectly to switch from HE to %HE.

 

The problem is: when I switch to %HE, it looses the %format I gave to the original measure.... If I change the "HE or %HE" measure's format to %, both measures HE, %HE will be in %... which is also wrong.

 

Anyone help me?

 

PS: "Case" is a measure: the max of the first column of a table 2x2 like below (thus, returning 1 or 2)

 

1    HE

2    %_HE

 

Which I use as data segmentation (the button to change from a measure to another in a visual). If I select HE, it filters the table, then the Case measure returns 1. If I select %_HE, Case returns 2.

4 REPLIES 4
v-yuezhe-msft
Employee
Employee

@Anonymous,

Please change your DAX to the following:

HE or %HE = SWITCH(TRUE();[Case]=1;[HE];[Case]=2;FORMAT([% HE];"percent");BLANK())


2.PNG1.PNG

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hello Lydia,

 

Thank you for your answer. However, I still have an issue.

 

I wrote as you told me to, although it works perfectly in a table, when I select a visual, it returns blank! 😞

 

HE or %HE = SWITCH(TRUE();
[Case] = 1; [HE];
[Case] = 2; FORMAT([% HE]; "percent");
BLANK())

 

Here, you can see that I selected "Em %" (to return %HE measure). On the right, the table returns correctly %HE for the measure "HE or %HE" in the right format. However, on the left, the visual is in blank.Here, you can see that I selected "Em %" (to return %HE measure). On the right, the table returns correctly %HE for the measure "HE or %HE" in the right format. However, on the left, the visual is in blank.When "HE" is selected, everything is OK.When "HE" is selected, everything is OK.

 

Why? 😞

 

Stachu
Community Champion
Community Champion

it turns to blank beacause FORMAT converts numeric value to text
you may consider having 2 measures - one with FORMAT for tables and second without it for visuals
not sure if there is a cleaner solution to it though



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

@Anonymous,

Could you please share sample data of your tables here so that I can reproduce the whole report?

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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