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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Bareak
New Member

Need help creating a visual

I am creating a column chart visual comparing the the past 5 years sales.  I created measures to calculate the YTD shipments for the past 5 years.  I am filtering on the current year (2021) to display the data.

 

Bareak_0-1627314635895.png

Bareak_1-1627314880705.png

 

Now I am trying to add these values to a visual, but I am needing them to be displayed as the year (x-axis) and the shipment amount(y-axis). I created the clustered bar chart and drug all the values over, but this is not visual I am looking for.  I am needing all the values to be in a single field so that I can see each year on the x-axis.  I am thinking I am need to somehow do a union on the values to put them in their own table so that the values are a single column instead of 6, but I'm not sure how to do that.  

 

Bareak_4-1627315172361.png

 

Bareak_3-1627315048677.png

 

Any help would be appreciated.

 

 

1 ACCEPTED SOLUTION
Bareak
New Member

I was able to solve this by using the video provided by Avi Singh: https://www.youtube.com/watch?v=WBddNp_25YY.  I modified the DAX formulas to work with my fiscal date calendar, then applied a filter on the visual to show the top N records.

 

Our data is batch loaded overnight, so I am using the current day minus 1 to determine the most recent fiscal day.

 

Max Fiscal Day = CALCULATE(MAX('Date Table'[FiscalDay]), ALL('Date Table'), 'Date Table'[Actual_Date_DT] = TODAY() - 1)
 
I modified the DAX in the video to:
 
Shipment YoY = VAR MaxDate = [Max Fiscal Day]
RETURN CALCULATE([Shipments],'Date Table'[FiscalDay] <= MaxDate)
 
This gives me my most recent Fiscal Day.  I can then drop in the visual and filter it on the top 6 records, sorted by fiscal year.
 
Bareak_0-1627496729388.png

 

Bareak_1-1627496782526.png

 

 

View solution in original post

9 REPLIES 9
Bareak
New Member

I was able to solve this by using the video provided by Avi Singh: https://www.youtube.com/watch?v=WBddNp_25YY.  I modified the DAX formulas to work with my fiscal date calendar, then applied a filter on the visual to show the top N records.

 

Our data is batch loaded overnight, so I am using the current day minus 1 to determine the most recent fiscal day.

 

Max Fiscal Day = CALCULATE(MAX('Date Table'[FiscalDay]), ALL('Date Table'), 'Date Table'[Actual_Date_DT] = TODAY() - 1)
 
I modified the DAX in the video to:
 
Shipment YoY = VAR MaxDate = [Max Fiscal Day]
RETURN CALCULATE([Shipments],'Date Table'[FiscalDay] <= MaxDate)
 
This gives me my most recent Fiscal Day.  I can then drop in the visual and filter it on the top 6 records, sorted by fiscal year.
 
Bareak_0-1627496729388.png

 

Bareak_1-1627496782526.png

 

 

m3tr01d
Continued Contributor
Continued Contributor

@Bareak Ok, I would try something like this first just to see if you are able to have the same results :

[YTD Shipments] =
--Get the last Shipment date
VAR _Latest_Shipment Date = CALCULATE(MAX(Shipments[Invoice Date]), ALL(Shipments))

--Use the last shipment date to calculate the YTD variation
RETURN
CALCULATE(
	[Total Shipments],
	DATESYTD(
		'DIM Date'[Cal Date]
	),
	'DIM Date'[Cal Date] = _Latest_Shipment,
	ALL( 'DIM Date'[Cal Date] )
)

[YTD Shipments 1YP] = 
VAR _Latest_Shipment Date = CALCULATE(MAX(Shipments[Invoice Date]), ALL(Shipments))

--Use the last shipment date to calculate the YTD variation for the previous year
RETURN
CALCULATE(
	[YTD Shipments],
	DATEADD(
		'DIM Date'[Cal Date],
		-1,
		YEAR
	)	
)

You will need to change some Column names and Table names based on your data.



I created the two measures above, appending Test to the measure name.

 

YTD Shipments Test = 
--Get the last Shipment date
VAR _Latest_ShipmentDate = CALCULATE(MAX(Shipments[Invoice Date]), ALL(Shipments))

--Use the last shipment date to calculate the YTD variation
RETURN
CALCULATE(
	[Total Shipments],
	DATESYTD(
		'Date Table'[Actual_Date_DT]
	),
	'Date Table'[Actual_Date_DT] = _Latest_ShipmentDate,
	ALL( 'Date Table'[Actual_Date_DT] )
)


YTD Shipments 1YP Test = 
VAR _Latest_Shipment_Date = CALCULATE(MAX(Shipments[Invoice Date]), ALL(Shipments))

--Use the last shipment date to calculate the YTD variation for the previous year
RETURN
CALCULATE(
	[YTD Shipments Test],
	DATEADD(
		'Date Table'[Actual_Date_DT],
		-1,
		YEAR
	)	
)

 

Here are the values returned compared to the current measures, previous measures on the left.

Bareak_0-1627324323814.png

 

 

m3tr01d
Continued Contributor
Continued Contributor

Ok, 
1) Can you tell me the code for measure Total Shipments?
2) Do you have any other filters on the Report or on the Card visuals?

Thank you for your help.

 

1)  

Total Shipments = round(sum('Shipments'[Ext Price]),2)

YTD Shipments = TOTALYTD([Total Shipments], 'Date Table'[Actual_Date_DT])

 

2)  The only report filter is at the page level and it is on the year (locked to 2021).

 

Bareak_0-1627324629496.png

 

 

 

m3tr01d
Continued Contributor
Continued Contributor

Hello @Bareak,

let's say you want to have these values on the X axis : 1YP, 2YP, 3YP, 4YP, 5YP

You could have a disconnected table with YearValues that would contain only one column with these values : 
1YP, 2YP, 3YP, 4YP, 5YP.

Then you can build a single measure that will use the value and adjust the calculation. It would help us if you provide us the DAX between your measures.


Thanks for the quick reply.  Here is the formula that I use to determine previous years YTD shipments.  For additional previous years, I change the 2 in the dateadd formula to 3, 4, 5.  Latest shipment date is a measure that finds the most recent date we have shipments.

 

YTD Shipments 2YP = calculate([Total Shipments], dateadd( INTERSECT (
VALUES ('Date Table'[Actual_Date_DT]),
DATESBETWEEN ('Date Table'[Actual_Date_DT], BLANK (), [Latest Shipment Date])
),-2,year))
 
Latest Shipment Date = CALCULATE(MAX(Shipments[Invoice Date]), ALL(Shipments))
m3tr01d
Continued Contributor
Continued Contributor

Ok so first, I would like to see if we can get this measure cleaner. 
If you have selected the year 2021 in your report. I assume :

YTD 1YP would be from Jan 1st 2020 to July 26th 2020?
YTD 2YP would be from Jan 1st 2019 to July 26th 2019?

Can you confirm if it's correct or give the correct date range for these examples

Yes, this is correct.

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.