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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
vespa
Regular Visitor

Help Dax Distinct

Hi

 

I have 2 measures : Turnover and Last Year Turnover

 

I want to have a measure in dax

 

Distinct customer who have turnover this year but not last year

Disctinct customer who have turnover last year but not this year

 

I try

 

CALCULATE (
    DISTINCTCOUNT(  '_Sales'[Customer] ),
    FILTER( '_Sales'   ,   '_Sales'[Turnover] > 0 && '_Sales'[TurnoverLastYear] = 0 )  
)
 
But it's not working, thank you in advance for your help 

 

4 REPLIES 4
vespa
Regular Visitor

Thank you very much, this clearly shows me the results for this year and last year.

How can I modify it so that it works for each year and its previous year? whether it is dynamic?

thanks in advance

Hi, @vespa 

in @Jihwan_Kim code modify like below

var _currentyear= selectedvalue(datetablename[yearcolumn])

to be more dynamic is it possible to use something to get current period et same period last year ?

Jihwan_Kim
Super User
Super User

Hi, I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

please check the below picture and the attached pbix file if it suits your requirement.

 

Jihwan_Kim_1-1703176257951.png

 

 

Jihwan_Kim_0-1703176225658.png

 

EXCEPT function (DAX) - DAX | Microsoft Learn

 

Only this year customers count: = 
VAR _currentyear =
    YEAR ( TODAY () )
VAR _lastyear = _currentyear - 1
VAR _thisyearlist =
    CALCULATETABLE (
        SUMMARIZE ( Sales, Customer[Customer] ),
        'Calendar'[Year] = _currentyear
    )
VAR _prevyearlist =
    CALCULATETABLE (
        SUMMARIZE ( Sales, Customer[Customer] ),
        'Calendar'[Year] = _lastyear
    )
VAR _onlythisyearlist =
    EXCEPT ( _thisyearlist, _prevyearlist )
RETURN
    CALCULATE ( COUNTROWS ( Customer ), _onlythisyearlist )
Only previous year customers count: = 
VAR _currentyear =
    YEAR ( TODAY () )
VAR _lastyear = _currentyear - 1
VAR _thisyearlist =
    CALCULATETABLE (
        SUMMARIZE ( Sales, Customer[Customer] ),
        'Calendar'[Year] = _currentyear
    )
VAR _prevyearlist =
    CALCULATETABLE (
        SUMMARIZE ( Sales, Customer[Customer] ),
        'Calendar'[Year] = _lastyear
    )
VAR _onlypreviousyearlist =
    EXCEPT ( _prevyearlist, _thisyearlist )
RETURN
    CALCULATE ( COUNTROWS ( Customer ), _onlypreviousyearlist )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.