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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
rqh
Frequent Visitor

Line Chart with Current Year and Prior Year values

Hi everyone!

My line chart has two lines: one for current year sales (CY) and the other for prior year sales (PY). For the most recent year, CY records stop in May. I would like for the chart to not display any months beyond May for the PY. I have a slicer for the years.

Any suggestions? 🙂

 

Screenshot 2024-01-19 143802.pngScreenshot 2024-01-19 150345.pngScreenshot 2024-01-19 151023.pngScreenshot 2024-01-19 151048.pngScreenshot 2024-01-19 151059.png

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Try this measure

PY net sales new = if([Net sales]=blank(),blank(),[net sales])

If this does not work, then share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
garreola
Regular Visitor

Hello I have the problem that I need to show the Current Year unitl it now i.e. February

However I need to show Prev Year with all months

garreola_0-1740426414960.png

 

Cantidad Comprada ThisYEARSelected =
 
IF( ISBLANK( [Cantidad Comprada] ) ,
    BLANK() ,
    CALCULATE( [Cantidad Comprada] ,
        DATEADD( addCalendarioComprasCat[FECHA_COMPRA] , 0 , YEAR ) )
)
 
 
Cantidad Comprada LastYEARSelected =
 
IF( ISBLANK( [Cantidad Comprada] ) ,
    BLANK() ,
    CALCULATE( [Cantidad Comprada] ,
        DATEADD( addCalendarioComprasCat[FECHA_COMPRA] , -1 , YEAR ) )
)
 
I use these formaulas because I'm using a filter selected to show the year the user wans to show
 
garreola_1-1740426588603.png

 

Thank you

 

rqh
Frequent Visitor

Hi everyone! Thank you for all the suggestions, I went ahead with @Ashish_Mathur's solution because it was the most straightforward approach.

Ashish_Mathur
Super User
Super User

Hi,

Try this measure

PY net sales new = if([Net sales]=blank(),blank(),[net sales])

If this does not work, then share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Daniel29195
Super User
Super User

@rqh 

create a calcuated column inside dimdate table that will return 1 or 0 base on this condition : 

new column =  

var max_date = max(table_name[date]) -- table_name =  the fact table on which your calculations are based,  such -- as net sales, gross sales ,...

 

RETURN 

switch(

true(),

dimdate[date] <=max_date , 1, 0 )

 

 

after you finish this column, 

put it in the filter pane on page level , and choose advanced filtering :  

is = 1 

 

this should fix your problem .

 

 

let me know if this would help .

 

best regards 

 

gmsamborn
Super User
Super User

Hi @rqh 

 

You could use a measure like this to filter your visual.

_Include = 
VAR _EndOfSales =
    MAXX(
        ALL( 'Sales'[Date] ),
        'Sales'[Date]
    )
VAR _EndOfMonth = EOMONTH( _EndOfSales, 0 )
VAR _Logic =
    IF(
        SELECTEDVALUE( 'Date'[Year] ) = BLANK(),
        1,
        IF(
            MAX( 'Date'[Date] ) > _EndOfMonth,
            0,
            1
        )
    )
RETURN
    _Logic

 

Let me know if you have any questions.

 

Filter PY visual.pbix

 



Proud to be a Super User!

daxformatter.com makes life EASIER!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.