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
justinMcC
Frequent Visitor

Turning a measure into a column

Hi,

 

I have a calculated measure on a table in PowerBi desktop report to categorise holdings as 'dairy' or 'beef' 

 

However I need to turn the data in table into a chart and I cannot use the measure on the legend or axis on chart. Below is the sample date:

 

HOLDINGID       CATEGORY (measure)

holding_1          dairy

holding_2          beef

holding_3          beef

 

On the chart I want to show Beef = 2 and Dairy = 1

 

How can I achieve this? can you turn a measure into a custom column?

 

Thanks for your help

 

 

1 ACCEPTED SOLUTION
v-jiascu-msft
Employee
Employee

Hi @justinMcC,

 

Here is two solutions based on your data and @WolfBiber's idea.

1. Calculated table.

CalculatedTableM1 = 
	ADDCOLUMNS(
		SUMMARIZE('Table1', 
				Table1[HoldingID], 
				"SumPercent_dairy", sum(Table1[percent_dairy])),
				"Category", if([SumPercent_dairy]>=80, "DAIRY","BEEF"))

2. Measure.

1) Create a new table "Category" by "Enter data" with data "Beef" and "Dairy". (don't create any relationships)

2) Create a measure.

Measure = var cat = min('CategoryTableM2'[Category]) 
	return sumx(
		ADDCOLUMNS(
			SUMMARIZE('Table1', 
				Table1[HoldingID], 
				"sumTemp", sum(Table1[percent_dairy])), 
				"categoryTemp", if([sumTemp]>=80,"DAIRY","BEEF")),
				if([categoryTemp] = cat, 1,0))

Turning_a_measure_into_a_column

 

Best Regards,

Dale

Community Support Team _ Dale
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

9 REPLIES 9
Anonymous
Not applicable

Hi Guys,

 

Hope all are doing good,

   I'm also facing the same issue from last few weeks onwards,But this is the basic thing but i'm unable to findout the way for below issue.

 

Percentage DAX :-

COUNT('Table'[Name])/CALCULATE(COUNT('Table'[Name]),ALLSELECTED('Name'))
Name Percentages
A24.36%
B20.51%
C15.30%
D8.97%
E6.41%
F6.41%
G6.41%
H5.13%
I3.85%
J2.56%

 

I want to display the categories based on percentages cutoff's

IF([Percentage]>= 10, "High","Low")
By default it was showing correct result only.But when  i was tried to apply some date range in filters  by using [Date] column .That time If function is not working.please check in below image.
 
ALow22.58%
BHigh19.35%
CLow16.13%
DLow16.13%
ELow12.90%
FLow9.68%
GHigh3.23%

 

If i write the same IF DAX by using CALCULATED MEASURE.It was showing correct result in all scenarios but i want to display as Pie chart. measures can't take in  Legend  right.

 

Appriciate for any help.

 

Regards,

Dinesh.

     

v-jiascu-msft
Employee
Employee

Hi @justinMcC,

 

Could you please mark the proper answer as solution?

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-jiascu-msft
Employee
Employee

Hi @justinMcC,

 

Here is two solutions based on your data and @WolfBiber's idea.

1. Calculated table.

CalculatedTableM1 = 
	ADDCOLUMNS(
		SUMMARIZE('Table1', 
				Table1[HoldingID], 
				"SumPercent_dairy", sum(Table1[percent_dairy])),
				"Category", if([SumPercent_dairy]>=80, "DAIRY","BEEF"))

2. Measure.

1) Create a new table "Category" by "Enter data" with data "Beef" and "Dairy". (don't create any relationships)

2) Create a measure.

Measure = var cat = min('CategoryTableM2'[Category]) 
	return sumx(
		ADDCOLUMNS(
			SUMMARIZE('Table1', 
				Table1[HoldingID], 
				"sumTemp", sum(Table1[percent_dairy])), 
				"categoryTemp", if([sumTemp]>=80,"DAIRY","BEEF")),
				if([categoryTemp] = cat, 1,0))

Turning_a_measure_into_a_column

 

Best Regards,

Dale

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

Would that work for this? I'm trying to get a monthly cummulative % total. ProductX does not work, as it's a measure from the data of Cash & Asset tables. Here are some screen shots.

Anonymous
Not applicable

Thaks for the amazing solution. I am very new to power bi and just implmented this solution.  However when i apply the same logic to my data, the slicer filters are not affecting on this table. The values remain constant in this. Is this how it works?  kindly suggest..thanks in advance

Greg_Deckler
Super User
Super User

You could potentially use the disconnected table trick as explained here:

 

https://community.powerbi.com/t5/Community-Blog/Solving-Attendance-with-the-Disconnected-Table-Trick...

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
WolfBiber
Employee
Employee

Hey,

you can add a calculated column.

A measure isnt 'bound' to a table, so if you want just to categorize your datarows, add a calculated column.

For any more help, please provide a pbix or at least some DAX.

Greetings.

Hi @WolfBiber

 

I have a table called 'holdings' with 2 measures to calculate if a holding percent_dairy >= x the 'dairy' else 'beef'

 

Measure 1:

Calculate_Dairy = CALCULATE(SUMX(holdings, holdings[percent_dairy]),ALLEXCEPT(holdings, holdings[holdingid]))

 

Measure 2:

Category = IF([Calculate_Dairy] >= [bvd_percent_2], "DAIRY","BEEF")

 

Table output example, if eg 'percent_dairy' >= 80

 

HOLDINGID         PERCENT_DAIRY       CATEGORY

holding_1            81                              DAIRY

holding_2            22                              BEEF

holding_3            44                              BEEF

 

Summary for chart:

 

Beef = 2, Dairy = 1

 

I tried putting the calculation in measure 2 into a calculated column, however all the results were listed as 'beef' regardless of 'percent_dairy' value

 

Any help you could give would be much appreciated

 

Hey,

maybe a calculated table is the right way for your purpose.

Find a entry point here :

https://docs.microsoft.com/en-us/power-bi/desktop-calculated-tables

 

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.