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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
mlozano
Helper II
Helper II

Formula Excel to DAX

Hello, I have a problem migrating a formula from excel to DAX.  My excel file is as follows:

 

mlozano_0-1654461428275.png

 

The formula that I am trying to replicate is the one in the red text called "NR/hl Cat Mix", in excel it is formulated as follows, it is really very simple:

 

(Peso SKU Act - Peso SKU Base) * (NR/Hl Cat Base - NR/Hl Total Base)

 

The formula in Excel is recalculated row by row, that is, every time I filter a dimension in my Excel table, the values ​​are recalculated row by row and depending on the applied filters there is always a new result.

 

when I try to replicate my excel formula in DAX, the behavior is completely different, I have no problem calculating the values ​​of the subtraction (Peso SKU Act - Peso SKU Base), both are percentage shares of each SKU ID over the total of each volume (LE Volume and ACT Volume), these in Excel as mentioned above, are calculated row by row in Excel, in DAX I do it as a Measure to be able to assign the same behavior from the recalculation that has the result in Excel.

 

My drawback is that when I subtract both actions in DAX, the result is 0, I have not been able to force the context of the row, I have already thought that the best solution would be a calculated column but I get static results, they are not recalculated according to the applied filters, so when adding, the result is very low or very high.

 

The shares in DAX, as a measure, I am calculating it like this:

 

Peso% SKU Act = DIVIDE(SUMX(Worksheet,[ACT Volume]),CALCULATE(SUM(Worksheet[ACT Volume]),ALLSELECTED(Worksheet)))

Peso% SKU Base = DIVIDE(SUMX(Worksheet,[LE Volume]),CALCULATE(SUM(Worksheet[LE Volume]),ALLSELECTED(Worksheet)))

 

As mentioned, the subtraction between both participations is 100%, so when subtracting them the result is 0. With the results of (NR/Hl Base Cat - NR/Hl Base Total), I have no problem. It's just that when you multiply it by 0, the result of "NR/hl Cat Mix" will always be 0, which is not correct.

 

I am sharing a sample of the data, which also contains the formula I want to replicate ("NR/hl Cat Mix"):

 

Sample Data 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @mlozano ,

 

Please try this.

NR/hl Cat Mix1 = 
SUMX(
SUMMARIZE(
    'Worksheet',
    'Worksheet'[Field 1 Name],
    'Worksheet'[Field 2 Name],
    'Worksheet'[Field 3 Name],
    'Worksheet'[Field 4 Name],
    'Worksheet'[Field 5 Name],

...

    'Worksheet'[NR/Hl Cat Base],
    'Worksheet'[NR/Hl Total  Base],
    "Act",[Peso% SKU Act],
    "Base",[Peso% SKU Base]
),
([Act]-[Base])*('Worksheet'[NR/Hl Cat Base]-'Worksheet'[NR/Hl Total  Base])
)

Attached PBIX file for reference.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

2 REPLIES 2
v-cgao-msft
Community Support
Community Support

Hi @mlozano ,

 

Please try this.

NR/hl Cat Mix1 = 
SUMX(
SUMMARIZE(
    'Worksheet',
    'Worksheet'[Field 1 Name],
    'Worksheet'[Field 2 Name],
    'Worksheet'[Field 3 Name],
    'Worksheet'[Field 4 Name],
    'Worksheet'[Field 5 Name],

...

    'Worksheet'[NR/Hl Cat Base],
    'Worksheet'[NR/Hl Total  Base],
    "Act",[Peso% SKU Act],
    "Base",[Peso% SKU Base]
),
([Act]-[Base])*('Worksheet'[NR/Hl Cat Base]-'Worksheet'[NR/Hl Total  Base])
)

Attached PBIX file for reference.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

The solution is perfect, thanks!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.