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
KARIM-K
Frequent Visitor

What function should I use to pass a measure result from one item to another

Hi All,

 

I need help please! I have built a data model in powerpivot to calculate the industrial losses by comparing the real quantity consumption to the theoretic BOM consumption based on the volume produced.

The data model looks working fine until I get stuck with the following issue: How to pass the theoretic consumption Quantity from Item 2 to Item 1 to obtain the following result:

- Item 1 quantity consumption = its initial Quantity + 1,8 x Quantity consumtion Item 2

- Item 2 quantity consumtion becomes 0

- All other items we keep the same quantity consumption unchanged

I have made many trials to overcome this issue but without success. I have tried SWITCH, IF function but I didn't succeed to get around it.

To showcase this issue, I have created the following dataset:

Item CodeItemQuantityUnit PriceSales

Item CodeItemQuantityUnit PriceSales
1Item 11002200
2Item 2503150
3Item 320480
4Item 410220
5Item 5515

 

The idea is to end up having the following result:

Item CodeItemQuantityUnit PriceSalesSales CONV
1Item 11002200350
2Item 25031500
3Item 32048080
4Item 41022020
5Item 55155
TOTAL   455455

 

Here are some of the trials I have made: 

 

Item CodeSALES FYSALES FY ITEM 1SALES FY ITEM 2SALES FY CONV
Item 1200200 200
Item 21501501500
Item 380  80
Item 420  20
Item 55  5
TOTAL455350150350

 

SALES FY = SUM(Tableau1[Sales])

SALES FY ITEM 1= CALCULATE(SUMX(Tableau1; [Sales]); FILTER(Tableau1; OR([Item Code]="1";[Item Code]="2")))

SALES FY ITEM 2 = CALCULATE(SUM(Tableau1[Sales]); Tableau1[Item Code] = "2")

SALES FY CONV = SWITCH(TRUE();

MIN(Tableau1[Item Code] )= "1"; CALCULATE(SUMX(Tableau1; [SALES FY]); FILTER(Tableau1; OR([Item Code] = "1"; [Item Code] ="2")));

MIN(Tableau1[Item Code]) = "2"; 0;

[SALES FY]

)

Thanks so much for your help!!!

4 REPLIES 4
wdx223_Daniel
Super User
Super User

wdx223_Daniel_0-1604885806134.png

SalesConv :=
VAR vSales_Of_Item2 =
    CALCULATE (
        SUM ( SampleData[Sales] ),
        SampleData[Item] = "Item2",
        ALL ( SampleData )
    )
RETURN
    SUMX (
        VALUES ( SampleData[Item] ),
        VAR vCurrentItem = SampleData[Item]
        RETURN
            IF (
                vCurrentItem = "Item1",
                vSales_Of_Item2 + CALCULATE ( SUM ( SampleData[Sales] ) ),
                IF ( vCurrentItem <> "Item2", CALCULATE ( SUM ( SampleData[Sales] ) ) )
            )
    )

Thank you so much for your help ! Eventhough I didn't fully understand the solution you provided but it worked great 🙂 

Could you please provide me with some more explanations about the solution and specially why do we need to use the All function adn what is the rational behind the function SUMX(VALUES

Thanks again and best regards 

AlB
Super User
Super User

Hi @KARIM-K 

How do you come up withj the 350 in the first row of the expected result?? It does NOT match the logic you provide:

Item 1 quantity consumption = its initial Quantity + 1,8 x Quantity consumtion Item 2

Can you explain?

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

KARIM-K
Frequent Visitor

Hi AIB,

 

Sorry for the mistake. You are right. For showcase purpose, I didn't apply the 1,8 gross up. I just added up the value of item 2 to item 1 and zero out item 2. It is the same logic but I have just changed the formula for simplicity purpose.

BR

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.

Top Solution Authors