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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
PeterRodet
New Member

Number of years with more then 2 invoices per year

Hello There, 

First of all, thank for your help. 

 

I am using powerpivot for the following analysis.

I would like to calculate the number of years (based on the transaction date) in which a client had more then 2 invoices in a year. The number of invoices should be calculated with distinctcount because if an invoice contains multiple products, the invoice number is repeated in the first column. Could anyone help me define a good measure?

 

This is +/- what my database looks like: 


Documentnr     Clientnr  Date         Product    Amount (€)

INV001-2018ABC1/03/2018Egg1
INV001-2018ABC1/03/2018Pineapple5
INV001-2018ABC1/03/2018Salad6
INV002-2018DEF5/04/2018Peppers3
INV003-2018ABC15/06/2018Peppers3
INV002-2018DEF5/04/2018Salad6
INV004-2018DEF16/10/2018Egg1
INV004-2018DEF16/10/2018Peppers3
INV001-2019ABC9/02/2019Sprouts4
INV001-2019ABC9/02/2019Peppers3
INV002-2019ABC18/11/2019Egg1
INV002-2019ABC18/11/2019Salad6
INV003-2019DEF12/12/2019Egg1

 

The result of this measure would be: 

ABC : 2 (because in 2018 en 2019 the client ABC had more then 1 invoice)

DEF: 1 (because the client DEF had only in 2018 2 invoices and in 2019 only 1 invoice).

 

Thanks a lot

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

First you need to add a calculated column to your table with this expression.  Replace documents with your actual table name in this and the measure below.

Year = YEAR(Documents[Date])
 
Then you can use this measure in a table visual with the Clientnr column to get your desired result.  This should also give you the correct total in the visual.
 

Years with >1 =
VAR vSummary =
    ADDCOLUMNS (
        SUMMARIZE (
            Documents,
            Documents[Clientnr],
            Documents[Year]
        ),
        "cDocs",
            CALCULATE (
                DISTINCTCOUNT ( Documents[Documentnr] )
            )
    )
RETURN
    COUNTROWS (
        FILTER (
            vSummary,
            [cDocs] >= 2
        )
    )

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
PeterRodet
New Member

It works! Thanks a lot Pat !

mahoneypat
Employee
Employee

First you need to add a calculated column to your table with this expression.  Replace documents with your actual table name in this and the measure below.

Year = YEAR(Documents[Date])
 
Then you can use this measure in a table visual with the Clientnr column to get your desired result.  This should also give you the correct total in the visual.
 

Years with >1 =
VAR vSummary =
    ADDCOLUMNS (
        SUMMARIZE (
            Documents,
            Documents[Clientnr],
            Documents[Year]
        ),
        "cDocs",
            CALCULATE (
                DISTINCTCOUNT ( Documents[Documentnr] )
            )
    )
RETURN
    COUNTROWS (
        FILTER (
            vSummary,
            [cDocs] >= 2
        )
    )

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.