cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
JBHCSS
Frequent Visitor

Find the difference between values in a group

I'm new to Power BI and I am struggling to figure out how to calculate the difference between values within a group. I want to calculate the difference between the amount for the values within a group compared to the lowest value within the group. 

PROJECTBID AMOUNTCOMPANYRANK
Alpha$113Mountaineers1
Alpha$119Wolfes2
Alpha$200Ram3
Beta$1,001Orders Co1
Beta$1,266J. Allen2
Beta$1,747Rock Forge3
Beta$2,803Angels, Inc4
Gamma$900Pavemaster1
Gamma$1,001Wonder Smash2

What I want to do is get the difference between each of the bid values and the value of the lowest bid, including the $0 difference for the lowest bid.

1 ACCEPTED SOLUTION
Nathaniel_C
Super User
Super User

Hi @JBHCSS ,
Try this:

 

Dif = 

Var _project = MAX(Difference[PROJECT])
Var _bidAmount = MAX(Difference[BID AMOUNT])

Var _minBidAmount = CALCULATE(MIN(Difference[BID AMOUNT]),FILTER(all(Difference),Difference[PROJECT]=_project))
Var _diff = _bidAmount-_minBidAmount

Return _diff


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

 





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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
Nathaniel_C
Super User
Super User

Hi @JBHCSS ,

So did you create a table called Difference? This is what I did in Power Query, and the wrote the measure in Power BI. Do you know  how to insert this code?

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZY9fC4IwFMW/yhg9jphTNB8tKAqiqAcfxIdhN432J6b1+btOUqSXnXs5v52dFQXN1KuRlNFFEIQoR/s2nXwYANfiGtCSzZgUJbfqDr0r5q7gHOUiNZ6ht9bQDfcY5wEOJ3fDXLKxY/REiDjG4bAkmVJgxvQJSKKkj7fVk2ytq+HvFcFWvP9DZmpQLSN7U+EWeWYntfZQ6kue5Qe0bDtwY5OR+JXNrcG25IpcM9Qpvw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PROJECT = _t, #"BID AMOUNT" = _t, COMPANY = _t, RANK = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"PROJECT", type text}, {"BID AMOUNT", Currency.Type}, {"COMPANY", type text}, {"RANK", Int64.Type}})
in
    #"Changed Type"

 

Try this, and then you can substitute your own table.


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




Nathaniel_C
Super User
Super User

Hi @JBHCSS ,
Try this:

 

Dif = 

Var _project = MAX(Difference[PROJECT])
Var _bidAmount = MAX(Difference[BID AMOUNT])

Var _minBidAmount = CALCULATE(MIN(Difference[BID AMOUNT]),FILTER(all(Difference),Difference[PROJECT]=_project))
Var _diff = _bidAmount-_minBidAmount

Return _diff


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

 





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

Proud to be a Super User!




I'm obviously doing something wrong because when I enter 

MAX(Difference[PROJECT])

or any of the other similar commands I get a "cannot find name" error for "Difference" and "PROJECT".

@JBHCSS,

 

Your table will look like this:

Nathaniel_C_0-1672957456741.png


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors