cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

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?

1 ACCEPTED SOLUTION
Employee

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

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

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!

Impactful Individual

Super User

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!

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.

Impactful Individual

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

Community Champion

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])))

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 😞

Thanks!

Super User

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!

Impactful Individual

Same values as I had 😞

Employee

@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])

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

Employee

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

Employee

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

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.
Impactful Individual

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

Super User

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!

Impactful Individual

What if I have multiple SKUs?

Super User

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!

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 😞

Announcements

#### Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.