Forum Discussion
Create a measure from Column Values
- 2 years ago
Hi HaroldqPants - In power query editor
Go to the Transform tab, and click on Pivot Column.
In the Pivot Column dialog, select 'KPIs' as the column to pivot, and 'Actuals' as the values column.
For the Advanced options, choose Don't Aggregate.Reference:
Go to the Add Column tab and click on Custom Column.
Click close & Apply to return to the Power BI report view.
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!! - Anonymous2 years ago
Hi HaroldqPants ,
rajendraongole1 Good Answer!
And HaroldqPants Not all data sources can use Power Query, it depends on your connection mode. Only in Import mode can you fully use Power Query. If you are in Direct Query mode, your Power Query will be limited, some functions cannot be used, and some data is not visible to you. If you are in Live Connection mode, you cannot use Power Query. In addition, if the data table is a calculated column or a calculated table, it is not visible in Power Query.
I can provide you with a method using DAX to achieve your needs.
Use the following DAX to create a measure:'Sales' divided by 'Units'_measure = VAR _CurrentProduct = MAX('Table'[Product]) VAR _Sales = CALCULATE( SUM('Table'[Actuals]), ALL('Table'), 'Table'[Product] = _CurrentProduct && 'Table'[KPIs] = "Sales" ) VAR _Units = CALCULATE( SUM('Table'[Actuals]), ALL('Table'), 'Table'[Product] = _CurrentProduct && 'Table'[KPIs] = "Units" ) RETURN DIVIDE(_Sales, _Units)
Use the following DAX to create a calculated column:'Sales' divided by 'Units' = VAR _CurrentProduct = 'Table'[Product] VAR _Sales = CALCULATE( SUM('Table'[Actuals]), ALL('Table'), 'Table'[Product] = _CurrentProduct && 'Table'[KPIs] = "Sales" ) VAR _Units = CALCULATE( SUM('Table'[Actuals]), ALL('Table'), 'Table'[Product] = _CurrentProduct && 'Table'[KPIs] = "Units" ) RETURN DIVIDE(_Sales, _Units)And the final output is as below:
Best Regards,
Dino Tao
If this post helps, then please consider Accept both of the answers as the solution to help the other members find it more quickly.
Hi HaroldqPants ,
rajendraongole1 Good Answer!
And HaroldqPants Not all data sources can use Power Query, it depends on your connection mode. Only in Import mode can you fully use Power Query. If you are in Direct Query mode, your Power Query will be limited, some functions cannot be used, and some data is not visible to you. If you are in Live Connection mode, you cannot use Power Query. In addition, if the data table is a calculated column or a calculated table, it is not visible in Power Query.
I can provide you with a method using DAX to achieve your needs.
Use the following DAX to create a measure:
'Sales' divided by 'Units'_measure =
VAR _CurrentProduct = MAX('Table'[Product])
VAR _Sales =
CALCULATE(
SUM('Table'[Actuals]),
ALL('Table'),
'Table'[Product] = _CurrentProduct && 'Table'[KPIs] = "Sales"
)
VAR _Units =
CALCULATE(
SUM('Table'[Actuals]),
ALL('Table'),
'Table'[Product] = _CurrentProduct && 'Table'[KPIs] = "Units"
)
RETURN
DIVIDE(_Sales, _Units)
Use the following DAX to create a calculated column:
'Sales' divided by 'Units' =
VAR _CurrentProduct = 'Table'[Product]
VAR _Sales =
CALCULATE(
SUM('Table'[Actuals]),
ALL('Table'),
'Table'[Product] = _CurrentProduct && 'Table'[KPIs] = "Sales"
)
VAR _Units =
CALCULATE(
SUM('Table'[Actuals]),
ALL('Table'),
'Table'[Product] = _CurrentProduct && 'Table'[KPIs] = "Units"
)
RETURN
DIVIDE(_Sales, _Units)
And the final output is as below:
Best Regards,
Dino Tao
If this post helps, then please consider Accept both of the answers as the solution to help the other members find it more quickly.
Thanks Dino,
Apologies for the delayed response. I'll try this and come back to you.
Appreciate the effort you went to, thanks again.