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

new table from mix of measures from other table and formulas

HELP!!!

 

This is what I want to create, a table that has a column of lines for a P&L and their corresponding values.

 

2018-10-22 12_03_49-P&L V2 - Power BI Desktop.png

 

I have a fact table that has some of the "line items" and corresponding values, but need to add in the line items for GP, GP%, Totals, EBIT, etc...

 

I thought this formula would do it but it gives me an error, "A table of multiple values was supplied where a single value was expected"  This is the formula I have"

 

$ = SWITCH(values('Fact Table'[Line Item]),

"Product Sales", [Amount (YTD)]*-1,

"Labour Sales", [Amount (YTD)]*-1,

"Total Sales", calculate([Amount (YTD)]*-1, filter('Fact Table', or('Fact Table'[Line Item] = "Product Sales", 'Fact Table'[Line Item] = "Labour Sales"))),

"Product GP", CALCULATE([Amount (YTD)]*-1, filter('Fact Table', 'Fact Table'[Line Item] = "Product Sales")) - calculate([Amount (YTD)]*-1, filter('Fact Table', 'Fact Table'[Line Item] = "Product Cost")),

"Total GP", calculate([Amount (YTD)]*-1, filter('Fact Table', 'Fact Table'[Line Item] = "Total Sales")) - CALCULATE([Amount (YTD)]*-1, filter('Fact Table', or('Fact Table'[Line Item] = "Product Cost", 'Fact Table'[Line Item] = "Labour Cost"))),

"Wages", CALCULATE([Amount (YTD)]*-1, filter('Fact Table', 'Fact Table'[Line Item] = "Labour Cost")),

"Property", [Amount (YTD)]*-1, "Vehicle", [Amount (YTD)]*-1,

"Other", [Amount (YTD)]*-1,

"Total Expenses", calculate([Amount (YTD)]*-1, FILTER('Fact Table', 'Fact Table'[Line Item] in {"Wages", "Property", "Vehicle", "Other"})),

"EBIT", calculate([Amount (YTD)]*-1, filter('Fact Table', or('Fact Table'[Line Item] = "Product Sales", 'Fact Table'[Line Item] = "Labour Sales"))) - calculate([Amount (YTD)]*-1, FILTER('Fact Table', 'Fact Table'[Line Item] in {"Wages", "Property", "Vehicle", "Other"})))

 

2018-10-22 12_04_05-P&L V2 - Power BI Desktop.png

 

HELP!!!  How do I make this work?!

 

 

 

 

3 REPLIES 3
Greg_Deckler
Super User
Super User

That's a lot of code. However, the issue is with the first line. Don't use VALUES, that returns a table and SWITCH is expecting a single value. Just get rid of the VALUES function. You may have other issues.

 

 

$ = SWITCH('Fact Table'[Line Item],
"Product Sales", [Amount (YTD)]*-1,
"Labour Sales", [Amount (YTD)]*-1,
"Total Sales", calculate([Amount (YTD)]*-1, filter('Fact Table', or('Fact Table'[Line Item] = "Product Sales", 'Fact Table'[Line Item] = "Labour Sales"))),
"Product GP", CALCULATE([Amount (YTD)]*-1, filter('Fact Table', 'Fact Table'[Line Item] = "Product Sales")) - calculate([Amount (YTD)]*-1, filter('Fact Table', 'Fact Table'[Line Item] = "Product Cost")),
"Total GP", calculate([Amount (YTD)]*-1, filter('Fact Table', 'Fact Table'[Line Item] = "Total Sales")) - CALCULATE([Amount (YTD)]*-1, filter('Fact Table', or('Fact Table'[Line Item] = "Product Cost", 'Fact Table'[Line Item] = "Labour Cost"))),
"Wages", CALCULATE([Amount (YTD)]*-1, filter('Fact Table', 'Fact Table'[Line Item] = "Labour Cost")),
"Property", [Amount (YTD)]*-1, "Vehicle", [Amount (YTD)]*-1,
"Other", [Amount (YTD)]*-1,
"Total Expenses", calculate([Amount (YTD)]*-1, FILTER('Fact Table', 'Fact Table'[Line Item] in {"Wages", "Property", "Vehicle", "Other"})),
"EBIT", calculate([Amount (YTD)]*-1, filter('Fact Table', or('Fact Table'[Line Item] = "Product Sales", 'Fact Table'[Line Item] = "Labour Sales"))) - calculate([Amount (YTD)]*-1, FILTER('Fact Table', 'Fact Table'[Line Item] in {"Wages", "Property", "Vehicle", "Other"})))

@ 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...

Hi @Anonymous,

 

Based on my test, the issue should be related your measure. Could you please share your pbix to me ?

 

Column = SWITCH(Survey[department],"A",1,"B",2,"C", CALCULATE([total],FILTER(Survey,OR(Survey[department]="A",Survey[department]="B"))))

switch.PNG

 

Regards,

Frank

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

Yup, a lot of formula!  

 

When I take out the values function at the beggining I get the error:

"A single value for column "Line Item" in table 'Fact Table' cannot be determined.  This can happen when a measure formula refers to a column that contains many values without specifiying an aggregation such as min, max, count, or sum to get a single result."

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.