Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Omega
Impactful Individual
Impactful Individual

Absolute at total

Dears,

 

I am currently trying to calculate the absolute difference between imports and exports at SKU level in the total. For the same SKU, I have imports and exports in every week. At the end of week 8, I'd like to check the absolute difference between Imports and Exports. How?

 

Power BI_2.PNG

1 ACCEPTED SOLUTION

@Omega,

Create the following measures and check if you get expected result.

NewMeasure = IF(COUNTROWS(VALUES(Table2[SKU]))=1,Table2[ABSDIFF],SUMX(VALUES(Table2[SKU]),[ABSDIFF]))
Measure 3 = [NewMeasure]/[ExportTotal]

1.PNG

Regards,
Lydia

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

24 REPLIES 24
Anonymous
Not applicable

Hi @Omega 

How did you get the redmarked number, that´s the number I´m after but can´t seem to be able to produce.

/Helena

vanessafvg
Super User
Super User

maybe im being daft but why dont you convert the number after you have done the calculation rather than creating absolute figures before you do the sum.  ie. * -1





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Omega
Impactful Individual
Impactful Individual

Can you please ellaborate further?

SUMX(Table2,ABS(Table2[Export]-Table2[Import])) * -1

 

(but like i say i could be being daft)





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




dedelman_clng
Community Champion
Community Champion

Can you share the code for your measure(s) ? PowerBI visuals don't total up columns and rows on measures - it calculates the measure based on the current filter context.

Omega
Impactful Individual
Impactful Individual

Measure = SUMX(Table2,ABS(Table2[Export]-Table2[Import]))

Your code is doing the absolute value, then summing.  You want to sum then do absolute value

 

Measure = ABS(SUMX(Table2, (Table2[Export]-Table2[Import])))

Omega
Impactful Individual
Impactful Individual

Thanks!!! My bad didn't realize I'm doing it wrong. Now, I want to take the total absolute value (470) and divide it by the total export per SKU (8510). I tried the following measure: 

 

Measure 2 = SUMX(Table2,[Measure])/SUMX(Table2,Table2[Export]) but I'm not getting correct % 😞

 

I even tried: Measure 2 = SUMX(Table2,[Measure])/SUM(Table2[Export]) but still wrong because it gets me the total export for all the SKUs 😞

 

Please advise. 

 

Thanks!

 

 

Measure 2 = divide(SUMX(Table2,[Measure]),SUMX(Table2,Table2[Export]))





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Omega
Impactful Individual
Impactful Individual

Same values as I had 😞

@Omega,

I can get your expected result by creating the following measures. How do you create visual in your scenario?

ABSDIFF = ABS(SUMX(Table2, (Table2[Export]-Table2[Import])))
ExportTotal = SUM(Table2[Export])
Measure 2 = DIVIDE(Table2[ABSDIFF],Table2[ExportTotal])
1.PNG


Regards,
Lydia Zhang

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

It's close but when you combine SKUs it won't give the correct value because PBI will calculate the difference at week level then sum up the difference at SKU level. My aim is to calculate the total exports and imports per SKU -> Apply ABSDIFF -> Sum ABSDIFF and the divide by total exports. 

@Omega,

What do you mean that "combine SKUs"? Could you please post the screenshot that how you create the visual and how are the incorrect value like?

Regards,
Lydia Zhang

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

Sorry I was on leave and couldn't reply any time soon. What I meant is to get the difference between exports and imports for each SKU and take the summation for this difference. 

 

In PBI, it doesn't take the difference at SKU level but at the lowest level which is in this case is Weeks. Due to that, the calculations are not correct. 

@Omega,

Create the following measures and check if you get expected result.

NewMeasure = IF(COUNTROWS(VALUES(Table2[SKU]))=1,Table2[ABSDIFF],SUMX(VALUES(Table2[SKU]),[ABSDIFF]))
Measure 3 = [NewMeasure]/[ExportTotal]

1.PNG

Regards,
Lydia

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

Thanks a lot!!! This is the solution I was looking for 😄

divide(SUMX(Table2,[Measure]),calculate(SUMX(Table2,Table2[Export]),sku = 8510))





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Omega
Impactful Individual
Impactful Individual

What if I have multiple SKUs?

divide(SUMX(Table2,[Measure]),calculate(SUMX(Table2,Table2[Export]), filter(table2, sku = 8510 && sku = 111))

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Omega
Impactful Individual
Impactful Individual

Thanks but again, this will not solve the problem. Assume that I have one million SKUs, I won't be able to type all 1 million SKUs 😞

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.