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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
clarkey1988
Helper II
Helper II

Count row values based on two criteria

Hi,

 

I have a specific route number called Nestle-12 that I invoice $14,100 each week. I need to divide this $14,100 by the number of orders for Nestle-12 for that given week.

 

So the 1st example below would be $14,100/9 = $1,566.67 each row.

 

The second example is week 48 where only 4 orders ran for Nestle-12 so would be $14,100/4 = $3525 per row.

 

How would I write this in DAX?

 

RouteNumberStopAKord_hdrnumberLegHeaderEndDateWeek Number Nestle Revenue  Nestle Week 40 Order Numbers Split Revenue
NESTLE-121437675621365869/28/2020 3:0940 $                         14,1009 $        1,566.67
NESTLE-121437674821365859/28/2020 5:1540 $                         14,1009 $        1,566.67
NESTLE-1214371915213581910/1/2020 6:2940 $                         14,1009 $        1,566.67
NESTLE-121435517521332209/28/2020 2:1340 $                         14,1009 $        1,566.67
NESTLE-121435516321332149/28/2020 4:0440 $                         14,1009 $        1,566.67
NESTLE-121435510321332059/28/2020 1:4540 $                         14,1009 $        1,566.67
NESTLE-121440226321408829/30/2020 6:4240 $                         14,1009 $        1,566.67
NESTLE-1214402261214088110/1/2020 5:0040 $                         14,1009 $        1,566.67
NESTLE-1214402253214087710/1/2020 4:3040 $                         14,1009 $        1,566.67

 

 

RouteNumberStopAKord_hdrnumberLegHeaderEndDateWeek Number   
NESTLE-1214573180216824911/27/2020 6:4548 $                         14,1004 $              3,525
NESTLE-1214570593216781611/27/2020 5:4548 $                         14,1004 $              3,525
NESTLE-1214570585216781211/27/2020 3:4548 $                         14,1004 $              3,525
NESTLE-1214550807216468011/27/2020 4:4048 $                         14,1004 $              3,525
1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

If you want that as a calculated column, then simply divide the second last column by the third last column.


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

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

If you want that as a calculated column, then simply divide the second last column by the third last column.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
littlemojopuppy
Community Champion
Community Champion

Hi @clarkey1988 

 

Try this...

Calculated Split Revenue = 
    VAR NestleRevenue =
        CALCULATE(
            AVERAGE('Nestle Revenue'[ Nestle Revenue ]),
            FILTER(
                ALL('Nestle Revenue'),
                'Nestle Revenue'[Week Number] = SELECTEDVALUE('Nestle Revenue'[Week Number])
            )
        )
    VAR WeeklyOrders =
        CALCULATE(
            DISTINCTCOUNT('Nestle Revenue'[ord_hdrnumber]),
            FILTER(
                ALL('Nestle Revenue'),
                'Nestle Revenue'[Week Number] = SELECTEDVALUE('Nestle Revenue'[Week Number])
            )
        )
    RETURN

    DIVIDE(
        NestleRevenue,
        WeeklyOrders,
        BLANK()
    )

 

littlemojopuppy_0-1609970185225.png

 

So I went a little beyond what you asked for...a measure to get the weekly order count would be the second variable...

WeeklyOrders =
        CALCULATE(
            DISTINCTCOUNT('Nestle Revenue'[ord_hdrnumber]),
            FILTER(
                ALL('Nestle Revenue'),
                'Nestle Revenue'[Week Number] = SELECTEDVALUE('Nestle Revenue'[Week Number])
            )
        )
ToddChitt
Super User
Super User

Create a specific Measure for the count of these rows, filtered for NESTLE-12:

NESTLE-12 COUNT = CALCULATE ( COUNTROWS ( 'TableName' ), [RouteNumber] = "NESTLE-12" )

 

This measure can still be sliced by weeks or any other dimension.

 

Now create the main calculation:

Split Revenue = DIVIDE ( [Nestle Revenue], [NESTLE-12 COUNT] )




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Top Solution Authors