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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Ramfeb27
Regular Visitor

Revenue lost in Next year

Hi Everyone, please help me on the below use case

 

I want to calculate Revenue lost in the next year value. In the below sample data, in the Lost column, whichever record is marked as 1 needs to multiply with the previous year revenue.
Ex: In the below data, Customer 9020 has 1 in the Lost column for 2021. So now, as per the business logic, it needs to multiply with the previous year revenue (1 * 486,715 (prev year revenue) = 486715).

 

Cus#YearRevenueLost
90192020     68,5050
90192021   472,8760
90192022   486,7150
90192023                -0
90192024     89,7250
90202020   486,7150
90202021     68,5051
90202022                -0
90202023   472,8760
90202024   792,5250
90212020   152,8960
90212021   258,4561
90212022   987,4560
90212023   258,7431
90212024   325,6980

 

Ex2: Customer 9021 has two 1's in 2021 & 2023 so his value should be:
(1 * 152,896) = 152,896
(1 * 258,743) = 258,743

 

So final output will be:

202020212022
0(486715 + 152896) = 639611258,743

 

Which is the best way, Measure or Calculated Column?

1 ACCEPTED SOLUTION
mariussve1
Super User
Super User

Hi @Ramfeb27 🙂

You can try this measure:

Lost Revenue Measure = 
VAR __PrevYear =
    SELECTEDVALUE ( Demo[Year] ) - 1
VAR __CustID =
    SELECTEDVALUE ( Demo[Cus#] )
VAR __PrevRevenue =
    LOOKUPVALUE ( Demo[Revenue], Demo[Year], __PrevYear, Demo[Cus#], __CustID )
RETURN
    IF ( SELECTEDVALUE ( Demo[Lost] ) = 1, __PrevRevenue )

 

Or if you prefer a calculated column:

Lost Revenue Calculated Column = 
    VAR __PrevYear = Demo[Year] - 1
    VAR __CustID = Demo[Cus#]
    VAR __PrevRevenue =
        LOOKUPVALUE ( Demo[Revenue], Demo[Year], __PrevYear, Demo[Cus#], __CustID )
    RETURN
        IF ( Demo[Lost] = 1, __PrevRevenue )

 

I just copied your tabel above and named it "Demo", and this is the result:

mariussve1_0-1740416805604.png

 


Br
Marius
BI Fabrikken
www.bifabrikken.no

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @Ramfeb27 ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
mariussve1
Super User
Super User

Hi @Ramfeb27 🙂

You can try this measure:

Lost Revenue Measure = 
VAR __PrevYear =
    SELECTEDVALUE ( Demo[Year] ) - 1
VAR __CustID =
    SELECTEDVALUE ( Demo[Cus#] )
VAR __PrevRevenue =
    LOOKUPVALUE ( Demo[Revenue], Demo[Year], __PrevYear, Demo[Cus#], __CustID )
RETURN
    IF ( SELECTEDVALUE ( Demo[Lost] ) = 1, __PrevRevenue )

 

Or if you prefer a calculated column:

Lost Revenue Calculated Column = 
    VAR __PrevYear = Demo[Year] - 1
    VAR __CustID = Demo[Cus#]
    VAR __PrevRevenue =
        LOOKUPVALUE ( Demo[Revenue], Demo[Year], __PrevYear, Demo[Cus#], __CustID )
    RETURN
        IF ( Demo[Lost] = 1, __PrevRevenue )

 

I just copied your tabel above and named it "Demo", and this is the result:

mariussve1_0-1740416805604.png

 


Br
Marius
BI Fabrikken
www.bifabrikken.no
Sahir_Maharaj
Super User
Super User

Hello @Ramfeb27,

 

Can you please try this approach:

Revenue_Lost_Next_Year = 
VAR PrevYear = SELECTEDVALUE('RevenueTable'[Year]) - 1
VAR Revenue_Lost =
    SUMX(
        FILTER(
            ALL('RevenueTable'),
            'RevenueTable'[Year] = PrevYear && 'RevenueTable'[Lost] = 1
        ),
        'RevenueTable'[Revenue]
    )
RETURN
    Revenue_Lost

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
SamanthaPuaXY
Helper II
Helper II

Hi @Ramfeb27 I'm not quite getting the logic that you want with example 2.

Cus#YearRevenueLost
90192020     68,5050
90192021   472,8760
90192022   486,7150
90192023                -0
90192024     89,7250
90202020   486,7150
90202021     68,5051
90202022                -0
90202023   472,8760
90202024   792,5250
90212020   152,8960
90212021   258,4561
90212022   987,4560
90212023   258,7431
90212024   325,6980

 

Ex2: Customer 9021 has two 1's in 2021 & 2023 so his value should be:
(1 * 152,896) = 152,896 -> This takes 2020 Customer 9021
(1 * 258,743) = 258,743 -> Isn't this supposed to take 2022 Customer 9021 which is 987,456?
And if there's the previous year revenue loss of 2022 is including 2023?

Helpful resources

Announcements