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

Subtract within column then divide

Hi, trying to write a measure for Variance%. There are lots of Date, First, Last and Shop which need to be matched before proceed to calculate the Variance %. Column Status will only consist of "Quote", "Actual" and "Forecast". Calculation is shown at right, i.e. Variance % = Quote minus Actual then divide by Quote; Forecast minus Actual then divide by Forecast

 

 


Capture4.PNG

 

 

Gurus out there, may you please help me! 

 

 

1 ACCEPTED SOLUTION
AnthonyTilley
Solution Sage
Solution Sage

so i would do this with two parts 

 

1 - create a calculated colunm for Key that is a uniqu key for each iteration of date,last,first,shop

KEY = [Date] & "-" & [First] & "-" & [Last] & "-" & [Shop]

tab.png

 

next create a measure as below

Measure = 
-- first define the key filed and status as veriables
var k = max('Table'[KEY])
var s = max('Table'[Status])
-- then caluclate the actual, forecast and qoute
var a = CALCULATE(sum('Table'[Value]), 'Table'[Status]= "actual", 'Table'[KEY] = k)
var f = CALCULATE(sum('Table'[Value]), 'Table'[Status]= "Forecast", 'Table'[KEY] = k)
var q = CALCULATE(sum('Table'[Value]), 'Table'[Status]= "Qoute", 'Table'[KEY] = k)
-- then calculate each of the possable values
var v1 = 0
var v2 = (a-f)/f
var v3 = (a-q)/q
--finaly switch values based on defined status
var ret = SWITCH(s,
                    "ACTUAL",v1,
                    "FORECAST",v2,
                    "QOUTE",v3,0)

return ret

simple put the measure first defines the two dimensions the key and the status 

it then calcualtes the actual, forecast and qoute for each of these dimentions and stores them in veriables 

it then usees these three veriables to create a set of values based on your calculations

the final step then switches between each of these values based on the status in the row 

 

measure.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
Anonymous
Not applicable

@parry2k , yes there is no common identifier.

 

@AnthonyTilley , you got it. This is what I want. New to DAX, will need to digest your solution. Thank you so much!

AnthonyTilley
Solution Sage
Solution Sage

so i would do this with two parts 

 

1 - create a calculated colunm for Key that is a uniqu key for each iteration of date,last,first,shop

KEY = [Date] & "-" & [First] & "-" & [Last] & "-" & [Shop]

tab.png

 

next create a measure as below

Measure = 
-- first define the key filed and status as veriables
var k = max('Table'[KEY])
var s = max('Table'[Status])
-- then caluclate the actual, forecast and qoute
var a = CALCULATE(sum('Table'[Value]), 'Table'[Status]= "actual", 'Table'[KEY] = k)
var f = CALCULATE(sum('Table'[Value]), 'Table'[Status]= "Forecast", 'Table'[KEY] = k)
var q = CALCULATE(sum('Table'[Value]), 'Table'[Status]= "Qoute", 'Table'[KEY] = k)
-- then calculate each of the possable values
var v1 = 0
var v2 = (a-f)/f
var v3 = (a-q)/q
--finaly switch values based on defined status
var ret = SWITCH(s,
                    "ACTUAL",v1,
                    "FORECAST",v2,
                    "QOUTE",v3,0)

return ret

simple put the measure first defines the two dimensions the key and the status 

it then calcualtes the actual, forecast and qoute for each of these dimentions and stores them in veriables 

it then usees these three veriables to create a set of values based on your calculations

the final step then switches between each of these values based on the status in the row 

 

measure.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




parry2k
Super User
Super User

@Anonymous do you have common identifier for each group or just name is the identifier to group rows together?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.