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
NH
Advocate II
Advocate II

Need help on DAX forumlae to calculate the Sale order count that has invoiced and uninvoiced

Hi

Hope someone can help to advise me the DAX forumale to count Sale order that has invoiced and no invoiced every month based on the  sale order table, invoice table. I've also created a date table.

 

Scenario is:

1. If the Sale  order month = Invoiced Month then count this SO ID has invoiced

2. If the Sale order has no invoiced date then count this SO ID as uninvoiced and has to check again for following month and so till it has invoiced date. 

3. Sale order that has invoiced on the current month (report month) will not included or count in the following month.

 

 

Example of my Sale Order table contain Sale Order ID ( SO ID) and Sale order date, Qty

Sale Order Table  
SO IDSO dateQty
111112-Dec-1710
222213-Dec-1720
333314-Dec-1715
444415-Dec-174
55552-Jan-181
66663-Jan-183
77774-Jan-184
888818-Jan-185
999919-Jan-187

 

Invoiced Table

Invoice Table  
SO IDInvoiced DateInvoice $
111116-Dec-17100
222217-Dec-18200
33333-Jan-18150
44442-Feb-1840
55554-Jan-1810
66667-Jan-1830
77774-Feb-1840
88883-Mar-1850
99994-Mar-1870

 

Expected Result

Output report   
Month YrInvoiced SO countUninvoiced SO countRemark
Dec 2017221111 & 2222 has invoiced in Dec while 2222 and 3333 was only happen to invoiced in Jan and Feb respectively
Jan 2018343333 was invoiced in Jan 18 with 5555, 6666 SO thus total Invoiced SO count for Jan was 3 while Uninvoiced SO count was 4 becos 4444, 7777, 8888, 9999 the invoiced date was happen on the following month or next

 

 

Thanks for the help in advance.

NH

4 REPLIES 4
afzalphatan
Resolver I
Resolver I

willl give it a try soon....

Zubair_Muhammad
Community Champion
Community Champion

Hi @NH

 

Please see the attached file here

 

Uninvoiced SO Count =
VAR AllOrders =
    CALCULATETABLE (
        VALUES ( SalesOrder[SO ID] ),
        FILTER (
            SalesOrder,
            SalesOrder[SO date] <= EOMONTH ( MAX ( Invoice[Invoiced Date] ), 0 )
        )
    )
VAR Allinvoices =
    CALCULATETABLE (
        VALUES ( Invoice[SO ID] ),
        FILTER (
            ALL ( Invoice ),
            Invoice[Invoiced Date] <= MAX ( Invoice[Invoiced Date] )
        )
    )
RETURN
    COUNTROWS ( EXCEPT ( AllOrders, Allinvoices ) )

Regards
Zubair

Please try my custom visuals

Still not able to figure out the correct DAX forumale. Your solution did help to provide the ideal.

 

 

Hi Zubair,

 

Appreaciate your prompt help. I will try it out and will update you soon. A quick check on your sample pbix file and notice the SO ID count is not what I'm looking for. 

The rule is count of Invoiced SO is:

SO ID in Sale oder table =  SO ID in the invoiced table

and

Sale order Month = Invoiced Month

Count = 1

Else if Sale order month < invoice Month (subsequce month, can be happen in m+1 o m+2, etc)

then consider this count of invoiced SO in the M+1 or M+2 , etc same the report month 

 

 

Sorry if my explaination is not clear

 

Thank you.

  

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.