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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Diego_Vialle
Helper II
Helper II

DAX - calculate invoices

Hello, I have a formula that filters customers who NEVER bought, but BUY in the last two months. Now I need the quantity of these invoices, each one has a different document number. I tried to change it within the formula to "Nº Documento" (which is the invoice number), without success.
Below is the formula used and the value in red that I need to find:

 

Diego_Vialle_0-1651530598851.png

 

Qtd. Faturamento Bimestral =
VAR AllOldCustomers =
CALCULATETABLE (
VALUES ( SBOPRODMS[Nº Documento] ),
SBOPRODMS,
SBOPRODMS[Data NF]
< TODAY () - 60,
SBOPRODMS[Documento] = "Nota fiscal de saída"
)
VAR AllNewCustomers =
CALCULATETABLE (
VALUES ( SBOPRODMS[Nº Documento] ),
SBOPRODMS[Data NF]
< TODAY () ,
SBOPRODMS[Documento] = "Nota fiscal de saída"
)
RETURN
COUNTROWS ( EXCEPT ( AllNewCustomers, AllOldCustomers ) )
1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Diego_Vialle 

you may tey

 

Qtd. Faturamento Bimestral =
VAR AllOldCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Customer] ),
        SBOPRODMS[invoice date]
            < TODAY () - 60,
        SBOPRODMS[document] = "outgoing invoice"
    )
VAR AllNewCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Customer] ),
        AND (
            SBOPRODMS[invoice date]
                >= TODAY () - 60,
            SBOPRODMS[document] = "outgoing invoice"
        )
    )
VAR NewCustomers =
    EXCEPT ( AllNewCustomers, AllOldCustomers )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( SBOPRODMS[Nº Documento] ),
        FILTER (
            SBOPRODMS,
            SBOPRODMS[Customer]
                IN NewCustomers
                && SBOPRODMS[document] = "outgoing invoice"
        )
    )

 

 

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

Hi @Diego_Vialle 

you may tey

 

Qtd. Faturamento Bimestral =
VAR AllOldCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Customer] ),
        SBOPRODMS[invoice date]
            < TODAY () - 60,
        SBOPRODMS[document] = "outgoing invoice"
    )
VAR AllNewCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Customer] ),
        AND (
            SBOPRODMS[invoice date]
                >= TODAY () - 60,
            SBOPRODMS[document] = "outgoing invoice"
        )
    )
VAR NewCustomers =
    EXCEPT ( AllNewCustomers, AllOldCustomers )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( SBOPRODMS[Nº Documento] ),
        FILTER (
            SBOPRODMS,
            SBOPRODMS[Customer]
                IN NewCustomers
                && SBOPRODMS[document] = "outgoing invoice"
        )
    )

 

 

Good afternoon friend, thanks again for your help. I believe it is correct.

In the Invoicing chart, when inserting the year and month of the Calendar table on the axis, the measure is being broken. How do I relate the Measurements table with the Calendar table?

 

Diego_Vialle_0-1651597402135.png

 

Diego_Vialle_1-1651597777881.png

 

 

 

 

amitchandak
Super User
Super User

@Diego_Vialle , Just change the duration and follow approach in my blog

 

Customer Retention Part 5: LTD Vs Period Retention
https://community.powerbi.com/t5/Community-Blog/Customer-Retention-Part-5-LTD-and-PeriodYoY-Retentio...

 

 

Rolling 2 =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = Date(Year(_max), month(_max) -2, Day(_max))+1,
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

LTD =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())

var _max= Date(Year(_max), month(_max) -2, Day(_max)),
var _min = Minx(ALLSELECTED('Date'),'Date'[Date])
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

How bought in last two month only

countx(values(Customer[Customer]) , if(isblank([LTD]) && not(isblank([Rolling 2])) , [Customer], Blank())

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.