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

Total Sales x Total Sales LY - Current year showing only until current month

Hi,

I have a fact table that I want to calculate the total sales for 2018, 2019, 2020, 2021 and 2022.

I am using a bar chart to compare the selected year total sales vs total sales last year.

I am using the two DAX functions below to calculate both measures and I got the result as expected.


*****************************************************
Total Sales =
SUMX( Fsales ,
fSales[REV_TRANSACTION_AMOUNT]
)

Total Sales LY =
CALCULATE(
[Total Sales],
SAMEPERIODLASTYEAR( dCalendar[Date] ))
*****************************************************

The problem is:

When I am visualizing the bar chart to the current year 2022, I am getting information on the columns August, September, October, November, and December from the last year only, which is obvious as I still don't have this information about my current year.

Does anyone know how I could work around it and not show information about TOTAL SALES LY to the future months of my current year?

 

 

- When selecting current 2022 I don't want to show Sep, Oct, Nov, and Dec

 

murillocosta_6-1660173130270.png

 

 

- When selecting years before current year (2022) it should shows like this

 

murillocosta_0-1660172964524.png

 

 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@murillocosta , Try measures like examples

 

SAMEPERIODLASTYEAR QTY forced=
var _max1 = COALESCE(maxx(allselected('Order'),'order'[Date]),today())
var _max2 = if(_max1 >today(),today(), _max1)
var _max = format(_max2,"MMDD")
return
calculate(Sum('order'[Qty]),SAMEPERIODLASTYEAR('Date'[Date]),filter('Date', format('Date'[Date],"MMDD")<=_max))

 

OR

 

SAMEPERIODLASTYEAR QTY forced=
var _max1 = COALESCE(maxx(allselected('Order'),'order'[Date]),today())
var _max2 = if(_max1 >today(),today(), _max1)
var _max = format(_max2,"MMDD")
return
if( format(max('Date'[Date]),"MMDD")<=_max, calculate(Sum('order'[Qty]),SAMEPERIODLASTYEAR('Date'[Date])), blank())

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@murillocosta , Try measures like examples

 

SAMEPERIODLASTYEAR QTY forced=
var _max1 = COALESCE(maxx(allselected('Order'),'order'[Date]),today())
var _max2 = if(_max1 >today(),today(), _max1)
var _max = format(_max2,"MMDD")
return
calculate(Sum('order'[Qty]),SAMEPERIODLASTYEAR('Date'[Date]),filter('Date', format('Date'[Date],"MMDD")<=_max))

 

OR

 

SAMEPERIODLASTYEAR QTY forced=
var _max1 = COALESCE(maxx(allselected('Order'),'order'[Date]),today())
var _max2 = if(_max1 >today(),today(), _max1)
var _max = format(_max2,"MMDD")
return
if( format(max('Date'[Date]),"MMDD")<=_max, calculate(Sum('order'[Qty]),SAMEPERIODLASTYEAR('Date'[Date])), blank())

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.

Top Solution Authors