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
Anonymous
Not applicable

Look for rows with the same value in one column and one of two items in another column

Hi All,

 

I’m very new to Power BI, so please forgive the obvious questions.

 

My manager would like me to use information from one of our databases to make a model of a proposed program. Some changes need to be made to the data from the database to fit parameters of the proposed program.

 

One of the things I need to find and correct is a double counting of two items in the original information. In the example below, Green Apples have been double counted so the number of green apples show up in both the Green Apples row and the Apples row for each store. This is only a problem when the store reports both Green Apples and Apples units.

 

I ultimately want to search for stores that report both Green Apples and Apples and then, for those stores only, have a Corrected Units figure for Apples that is equal to the original Apples Units minus the original Green Apples Units. All other rows would have a Corrected Units figure that is the same number as in the original Units column.

 

Right now I'm just trying to figure out how to search for rows with the same value in the Store column and either "Green Apples" or "Apples" in the Item column. I’ve played with Lookupvalue but I can’t figure out how to get the formula to look for the two different text strings in the same column.

 

Does anybody have any tips?

 

Thanks in advance for your help!

 

STORE        || ITEM               || UNITS               || Wanted Results: Corrected Units

Uptown      || Apples            ||     7                   ||        7

Uptown      || Strawberries   ||     9                   ||        9

Uptown      || Grapes            ||     4                   ||        4

Downtown || Apples             ||     5                   ||        2  (The units of Green Apples are subtracted from the units of Apples (5-3=2).

Downtown || Green Apples  ||     3                   ||        3

Downtown || Pears               ||     10                 ||        10

Suburbs     || Green Apples  ||     1                   ||        1

Suburbs     || Cantaloupes    ||     6                   ||        6

Suburbs     || Pineapples       ||     2                   ||        2

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @Anonymous,

 

Please create a calculated column with this formula:

Wanted Units =
IF (
    'Fruit Table'[ITEM] = "Apples",
    'Fruit Table'[UNITS]
        - CALCULATE (
            SUM ( 'Fruit Table'[UNITS] ),
            FILTER (
                ALLEXCEPT ( 'Fruit Table', 'Fruit Table'[STORE] ),
                'Fruit Table'[ITEM] = "Green Apples"
            )
        )
        + 0,
    'Fruit Table'[UNITS]
)

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

 

Will there only be a Green Apples there or can there by Red apples, Yellow bananas as well?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi Ashish,

 

Right here we’re only talking about the Green Apples and Apples.

 

In the information our database is giving to me there won’t be any Red Apples but I will be gathering the Yellow Bananas and Green Bananas units into a single line under Bananas. Also, those Grapes are going to get divided into Green Grapes and Red Grapes, both with and without seeds.

 

And that is all just to get ready to do the work on the actual model.

 

It’s going to be great fun and you’ll probably be seeing more of my questions.

 

Thanks!

v-yulgu-msft
Employee
Employee

Hi @Anonymous,

 

Please create a calculated column with this formula:

Wanted Units =
IF (
    'Fruit Table'[ITEM] = "Apples",
    'Fruit Table'[UNITS]
        - CALCULATE (
            SUM ( 'Fruit Table'[UNITS] ),
            FILTER (
                ALLEXCEPT ( 'Fruit Table', 'Fruit Table'[STORE] ),
                'Fruit Table'[ITEM] = "Green Apples"
            )
        )
        + 0,
    'Fruit Table'[UNITS]
)

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi Yuliana,

 

Awesome! That works!!

 

Can you tell me what purpose the “+ 0,” in the third to last line serves? I removed it and the formula still works.

 

Thanks so much for your help!

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.