Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hello everyone, good afternoon.
I need help with my data analysis project in Power BI.
Objective: Format the measure inserted in the 2 graphs that I use to compare the selected parameters.
Context: The project is comparative, the comparison compares two periods period a (first date) period b (second date). The project works well,
it contains 3 main graphs. The first graph uses a parameter, that is, when the user clicks on ''Compare Net Revenue'', all measures are focused on net revenue, when clicking on ''Compare Discount'' it returns all measures for discount, etc. The general is Measure[Period A], Measure[Period B] and the difference between A and B (how much it increased or decreased from the first period to the second period). Problems/Challenges: I have 2 graphs (one for period A and another for period B), according to the selected parameter, each graph returns the parameter only for period A and B, and so it is more of a timeline comparison. The measure I used was the following: % vG_Period_A =
SWITCH(
TRUE(),
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)])="Compare Net Revenue",[Net Revenue A], SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)])="Compare Discount",[Discount A],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)])="Compare Gross Revenue",[Gross Revenue A],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)])="Compare Daily Average",[Daily Average A],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)])="Compare P.A.",[P.A. A],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)])="Compare M.P.",[M.P. A],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)])="Compare Qty. Coupons",[Number of Coupons A],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)])="Compare Days Worked",[Number of Days Worked A],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)])="Compare Number of Items",[Number of Items A],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)])="Compare Average Ticket",[Average Ticket A]
)
The problem is that I can't use the formatting of the measure, for example:
The discount is a monetary value, and it only appears as a decimal number with 2 places
The net and gross revenue are also monetary, and they also appear as decimal numbers with 2 places. It's as if I could only choose one formatting for the selected measure.
What I tried to do to solve it: I've already tried using the format(It gave an error in the measure, it seems that (the format is only for texts).
The closest thing that came to working was creating separate measures according to the formatting, for example:
I created a switch to return this same measure only for monetary values, another only for decimal numbers with one place and another for decimal numbers with two places. It worked, the problem is that this way it limits my graph a lot and does not allow me to place the values above the bars.
If you have any ideas, I would appreciate it.
Solved! Go to Solution.
Hi @YagoXavier
Thank you for using Microsoft Community Forum.
The issue you're experiencing is due to how the FORMAT() function works in DAX. While FORMAT() can apply specific numeric formats like currency or decimal places, it converts the result into a text data type. This means visuals like bar and column charts, which require numeric values for rendering and aggregations (e.g., tooltips, data labels), cannot interpret the formatted output correctly, leading to visuals disappearing or behaving unexpectedly.
To dynamically apply formatting based on the selected comparison parameter without converting your measure to text, we recommend using Calculation Groups via Tabular Editor. Calculation Groups allow you to define both the expression and the numeric format string separately, preserving the numeric data type while enabling the desired formatting (such as currency, whole number, or decimal) depending on the user’s slicer selection. This approach resolves the formatting limitation cleanly and is the officially supported method for dynamic formatting in Power BI.
If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.
@YagoXavier Create measures for each parameter with the appropriate formatting.
DAX
NetRevenueA = FORMAT([Net Revenue A], "Currency")
DiscountA = FORMAT([Discount A], "Currency")
GrossRevenueA = FORMAT([Gross Revenue A], "Currency")
DailyAverageA = FORMAT([Daily Average A], "0.00")
PAA = FORMAT([P.A. A], "0.00")
MPA = FORMAT([M.P. A], "0.00")
NumberOfCouponsA = FORMAT([Number of Coupons A], "0")
NumberOfDaysWorkedA = FORMAT([Number of Days Worked A], "0")
NumberOfItemsA = FORMAT([Number of Items A], "0")
AverageTicketA = FORMAT([Average Ticket A], "Currency")
Use a SWITCH statement to dynamically select the appropriate formatted measure based on the selected parameter.
DAX
% vG_Period_A_Formatted =
SWITCH(
TRUE(),
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)]) = "Compare Net Revenue", [NetRevenueA],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)]) = "Compare Discount", [DiscountA],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)]) = "Compare Gross Revenue", [GrossRevenueA],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)]) = "Compare Daily Average", [DailyAverageA],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)]) = "Compare P.A.", [PAA],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)]) = "Compare M.P.", [MPA],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)]) = "Compare Qty. Coupons", [NumberOfCouponsA],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)]) = "Compare Days Worked", [NumberOfDaysWorkedA],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)]) = "Compare Number of Items", [NumberOfItemsA],
SELECTEDVALUE('Comparison Pair'[Comparison Pair (groups)]) = "Compare Average Ticket", [AverageTicketA]
)
Replace the original measure in your visuals with the new dynamic measure % vG_Period_A_Formatted.
Proud to be a Super User! |
|
Hello bhanu_guatam
First of all, thank you for answering and trying to solve my problem, but the same thing happened when I tried to use the format in the switch or in the measurement itself.
It gives an error and the bar doesn't appear, I believe the format is only for using text.
I'm going to try something related to the design groups to test or else put the "measurement types" (currency, decimal number with 1 place and decimal number with 2 places) in the measurement and try another look. This one has worked best so far, the only problem is that it greatly limited the formatting of my measurement. If you succeed, come back here to comment, it might help someone.
Thanks bhanu_guatam.
Hi @YagoXavier
Thank you for using Microsoft Community Forum.
The issue you're experiencing is due to how the FORMAT() function works in DAX. While FORMAT() can apply specific numeric formats like currency or decimal places, it converts the result into a text data type. This means visuals like bar and column charts, which require numeric values for rendering and aggregations (e.g., tooltips, data labels), cannot interpret the formatted output correctly, leading to visuals disappearing or behaving unexpectedly.
To dynamically apply formatting based on the selected comparison parameter without converting your measure to text, we recommend using Calculation Groups via Tabular Editor. Calculation Groups allow you to define both the expression and the numeric format string separately, preserving the numeric data type while enabling the desired formatting (such as currency, whole number, or decimal) depending on the user’s slicer selection. This approach resolves the formatting limitation cleanly and is the officially supported method for dynamic formatting in Power BI.
If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.
Hi @YagoXavier
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.
Hi @YagoXavier
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.
Hi @YagoXavier
Thank you for being part of the Microsoft Fabric Community.
User | Count |
---|---|
84 | |
78 | |
70 | |
47 | |
41 |
User | Count |
---|---|
108 | |
53 | |
50 | |
40 | |
40 |