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
AH2022
Helper I
Helper I

DAX Function get sales from Clients with sales previous 3 Fiscal Years and no sale This Fiscal Year

Hi All,

 

I am struggling getting the following DAX function: I need to display the clients and their sales for those clients who have consecutive sales on FiscalYR-3, FiscalYR-2, FiscalYR-1 but not This FiscalYR.

 

I found this code, but it does not seem to answer. Solved: Re: Calculating Consecutive Years Active - Microsoft Power BI Community

 

Regards and thanks!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your dataset looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file. I hope the below can provide some ideas on how to create a slolution for your dataset.

 

Picture1.png

 

Sales: = 
SUM( Data[Revenue] )

 

Customers list expected result: =
VAR _currentyear =
    YEAR ( TODAY () )
VAR _oneyearago = _currentyear - 1
VAR _twoyearsago = _currentyear - 2
VAR _threeyearsago = _currentyear - 3
VAR _currentyearnosalescustomers =
    SUMMARIZE (
        FILTER (
            CROSSJOIN ( VALUES ( 'Calendar'[Year] ), VALUES ( Customer[Customer] ) ),
            'Calendar'[Year] = _currentyear
                && [Sales:] = BLANK ()
        ),
        Customer[Customer]
    )
VAR _oneyearagocustomerslist =
    SUMMARIZE (
        FILTER (
            CROSSJOIN ( VALUES ( 'Calendar'[Year] ), VALUES ( Customer[Customer] ) ),
            'Calendar'[Year] = _oneyearago
                && [Sales:] <> BLANK ()
        ),
        Customer[Customer]
    )
VAR _twoyearagocustomerslist =
    SUMMARIZE (
        FILTER (
            CROSSJOIN ( VALUES ( 'Calendar'[Year] ), VALUES ( Customer[Customer] ) ),
            'Calendar'[Year] = _twoyearsago
                && [Sales:] <> BLANK ()
        ),
        Customer[Customer]
    )
VAR _threeyearagocustomerslist =
    SUMMARIZE (
        FILTER (
            CROSSJOIN ( VALUES ( 'Calendar'[Year] ), VALUES ( Customer[Customer] ) ),
            'Calendar'[Year] = _threeyearsago
                && [Sales:] <> BLANK ()
        ),
        Customer[Customer]
    )
RETURN
    CONCATENATEX (
        INTERSECT (
            INTERSECT (
                INTERSECT ( _currentyearnosalescustomers, _oneyearagocustomerslist ),
                _twoyearagocustomerslist
            ),
            _threeyearagocustomerslist
        ),
        Customer[Customer],
        ", "
    )

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.


Go to My LinkedIn Page


View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your dataset looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file. I hope the below can provide some ideas on how to create a slolution for your dataset.

 

Picture1.png

 

Sales: = 
SUM( Data[Revenue] )

 

Customers list expected result: =
VAR _currentyear =
    YEAR ( TODAY () )
VAR _oneyearago = _currentyear - 1
VAR _twoyearsago = _currentyear - 2
VAR _threeyearsago = _currentyear - 3
VAR _currentyearnosalescustomers =
    SUMMARIZE (
        FILTER (
            CROSSJOIN ( VALUES ( 'Calendar'[Year] ), VALUES ( Customer[Customer] ) ),
            'Calendar'[Year] = _currentyear
                && [Sales:] = BLANK ()
        ),
        Customer[Customer]
    )
VAR _oneyearagocustomerslist =
    SUMMARIZE (
        FILTER (
            CROSSJOIN ( VALUES ( 'Calendar'[Year] ), VALUES ( Customer[Customer] ) ),
            'Calendar'[Year] = _oneyearago
                && [Sales:] <> BLANK ()
        ),
        Customer[Customer]
    )
VAR _twoyearagocustomerslist =
    SUMMARIZE (
        FILTER (
            CROSSJOIN ( VALUES ( 'Calendar'[Year] ), VALUES ( Customer[Customer] ) ),
            'Calendar'[Year] = _twoyearsago
                && [Sales:] <> BLANK ()
        ),
        Customer[Customer]
    )
VAR _threeyearagocustomerslist =
    SUMMARIZE (
        FILTER (
            CROSSJOIN ( VALUES ( 'Calendar'[Year] ), VALUES ( Customer[Customer] ) ),
            'Calendar'[Year] = _threeyearsago
                && [Sales:] <> BLANK ()
        ),
        Customer[Customer]
    )
RETURN
    CONCATENATEX (
        INTERSECT (
            INTERSECT (
                INTERSECT ( _currentyearnosalescustomers, _oneyearagocustomerslist ),
                _twoyearagocustomerslist
            ),
            _threeyearagocustomerslist
        ),
        Customer[Customer],
        ", "
    )

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.


Go to My LinkedIn Page


Perfect! really appreciate!

Thank you @Jihwan_Kim 

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.