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

Countif in Power BI

Hi all,

 

I have a table in Power BI that has the concat of order number and order line and a total net value assigned for each combination. The problem is that the same combination of order number/line appears many times. I'm trying to get the total value only once for that combination of order number and line, and not the sum. I did the formula in Excel with a countif to bring back 1 as a result of only one combination, and then I multiplied by the total value; however, I haven't been able to find the equivalent to that formula in Power BI.

Here's is a ver simple example in Excel of what I'm looking for. 

 

Order no      Order line           Concat             Value           Distinct

123456              10                  12345610             5                   5

123456              20                  12345620             3                   3

123456              10                  12345610             5

123456              20                  12345620             3

123456              10                  12345610             5

123456              20                  12345620             3

123457              10                  12345710             2                   2

 

I hope someone can help me what a formula that could work in Power BI.

 

 

 

Thank you

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

What @amitchandak said is like this:

 

1. Add an Index column in Power Query Editor.

index.jpg

 

2. Create a column in Power BI Desktop Data view.

Column =
VAR MinIndex =
    CALCULATE (
        MIN ( 'Table'[Index] ),
        FILTER (
            'Table',
            'Table'[Order no] = EARLIER ( 'Table'[Order no] )
                && 'Table'[Order line] = EARLIER ( 'Table'[Order line] )
        )
    )
RETURN
    IF ( 'Table'[Index] = MinIndex, 'Table'[Value] )

 index.PNG

 

BTW, .pbix file attached.

 

 

 

Best Regards,

Icey

 

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

7 REPLIES 7
jdbuchanan71
Super User
Super User

@Anonymous 

If you want to do it with a measure give something like this a try.

 

Measure = 
SUMX(SUMMARIZE('Table','Table'[order nb],'Table'[order line]),CALCULATE(MAX('Table'[value])))

 

 

2020-06-25_8-39-46.png

*edit slight tweek to get the total correct.

 

Anonymous
Not applicable

Hi,

 

Thank you very much for your help!

Unfortunately it didn't work, it brings back the same number to each of the rows 😞

 

silviacarbajal_0-1593099570545.png

 

Right, mine is meant as a measure not a calculated column.  If you need to have a calculated column the solution form @amitchandak  is the way to go.

Also, if you use my measure please note I make a slight tweek to it after I first posted it.

amitchandak
Super User
Super User

@Anonymous , You have add a index colum and then add then find the min for order no , order using earlier and put value there

Anonymous
Not applicable

Hi @amitchandak can you please explain the answer again?
I didn't get your answer.

Thank you!

Icey
Community Support
Community Support

Hi @Anonymous ,

 

What @amitchandak said is like this:

 

1. Add an Index column in Power Query Editor.

index.jpg

 

2. Create a column in Power BI Desktop Data view.

Column =
VAR MinIndex =
    CALCULATE (
        MIN ( 'Table'[Index] ),
        FILTER (
            'Table',
            'Table'[Order no] = EARLIER ( 'Table'[Order no] )
                && 'Table'[Order line] = EARLIER ( 'Table'[Order line] )
        )
    )
RETURN
    IF ( 'Table'[Index] = MinIndex, 'Table'[Value] )

 index.PNG

 

BTW, .pbix file attached.

 

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

@Icey thank you SO much for your help. It finally worked!! 🙂

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.