Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
I have a matrix that shows different measures for individual groups.
The groups are segmented on the rows:
Group | Measure 1 | Measure 2 |
A | 1K | 3K |
B | 500 | 300 |
C | 2K | 3K |
Total | 3.5K | 6.3K |
Is it possible to define the format for a measure based on the selected group? As you can see the K format is only applicable for Group A and C.
Solved! Go to Solution.
Hi @joshua1990
You can refer to the following solution.
1.Create a new table, there is no relationship between the tables.
Table 2 = var a=VALUES('Table'[Group])
var b={"Total"}
return UNION(a,b)
2.Create the following measures.
Measure3 =
IF (
SELECTEDVALUE ( 'Table 2'[Group] ) <> "Total",
CALCULATE ( [Measure], 'Table'[Group] IN VALUES ( 'Table 2'[Group] ) ),
SUMX ( ALLSELECTED ( 'Table'[Group] ), [Measure] )
)
Measure4 =
IF (
SELECTEDVALUE ( 'Table 2'[Group] ) <> "Total",
CALCULATE ( [Measure 2], 'Table'[Group] IN VALUES ( 'Table 2'[Group] ) ),
SUMX ( ALLSELECTED ( 'Table'[Group] ), [Measure 2] )
)
Then change the format measure to the following.
Format_measure = IF(SELECTEDVALUE('Table 2'[Group]) in {"A","C","Total"},"#,##0,.0 K")
Then put the format measure to the format of measure3 and measure4. and create a matrix visual ,and put the field of table(2) to the row ,and put the measure3 and measure4 to the value, and close the row subtotals.
Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hope this video halps:
Power BI: Create & Apply Custom Format Strings for Measures
Hi,
Thanks for the solution FarhanJeelani and FreemanZ offered, and i want to offer some more information for user to refer to.
hello @joshua1990, you can use dynamic format, you can create a new measure.
Format_measure = IF(SELECTEDVALUE('Table'[Group]) in {"A","C"},"#,##0,.0 K")
Then click the measure1 and measure2, select Measure tool->format->dynamic
Then you can put the format measure to the related field.
Output
You can refer to the following link about the dynamic format.
Create dynamic format strings for measures in Power BI Desktop - Power BI | Microsoft Learn
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
THanks a lot @v-xinruzhu-msft.
Is it possible to get the total in thousand as well?
Hi @joshua1990
You can refer to the following solution.
1.Create a new table, there is no relationship between the tables.
Table 2 = var a=VALUES('Table'[Group])
var b={"Total"}
return UNION(a,b)
2.Create the following measures.
Measure3 =
IF (
SELECTEDVALUE ( 'Table 2'[Group] ) <> "Total",
CALCULATE ( [Measure], 'Table'[Group] IN VALUES ( 'Table 2'[Group] ) ),
SUMX ( ALLSELECTED ( 'Table'[Group] ), [Measure] )
)
Measure4 =
IF (
SELECTEDVALUE ( 'Table 2'[Group] ) <> "Total",
CALCULATE ( [Measure 2], 'Table'[Group] IN VALUES ( 'Table 2'[Group] ) ),
SUMX ( ALLSELECTED ( 'Table'[Group] ), [Measure 2] )
)
Then change the format measure to the following.
Format_measure = IF(SELECTEDVALUE('Table 2'[Group]) in {"A","C","Total"},"#,##0,.0 K")
Then put the format measure to the format of measure3 and measure4. and create a matrix visual ,and put the field of table(2) to the row ,and put the measure3 and measure4 to the value, and close the row subtotals.
Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
In Power BI, you can create different formats for measures based on the group by using a conditional formatting approach in DAX. Here’s how you can accomplish this:
1. Define the Custom Formatting in DAX: Create a DAX measure that formats the values conditionally based on the group.
2. Use SWITCH for Conditional Formatting: You can use `SWITCH` along with `FORMAT` to apply different formats depending on the group.
Here’s an example DAX measure to achieve this:
DAX
Formatted Measure =
SWITCH(
TRUE(),
'YourTable'[Group] = "A", FORMAT([Measure], "0K"),
'YourTable'[Group] = "C", FORMAT([Measure], "0K"),
FORMAT([Measure], "0")
)
In this example:
- For Group A and C, the measure will display in "K" format (thousands).
- For other groups, it will use the default format.
### Important Note
This approach works well for creating text-based formats in a matrix visual. However, because `FORMAT` converts numbers to text, this might affect sorting and aggregations, as Power BI treats them as text values.
If you need both numeric sorting and dynamic formatting, another approach would involve creating separate columns or measures and applying formatting in the matrix visual directly, but this is often more complex.
Let me know if you'd like further customization!
hi @joshua1990 ,
try like:
Measure 1b =
IF(
MAX(data[group]) IN {"A", "C"},
[Measure 1]/1000 &" K",
[Measure 1]
)
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
147 | |
85 | |
66 | |
52 | |
46 |
User | Count |
---|---|
215 | |
90 | |
83 | |
66 | |
58 |