Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I have a page for my report that includes a year slicer (with a dropdown for Current Year, 2022, 2021, etc..). The slicer is based on a date table that ranges from 2020 up to year 2050. The table is unique in which it only contains the first day of every month (January 1, 2020, Feb 1, 2020, etc...)
I am trying to calculate the sales of the prior year YTD. The measure I am using is incorrect as it returns $0. If the year slicer is set to 2022, the measure below should return the YTD sales of 2021, from Jan 2021 to September 6, 2021 (at the time of this writing). The year slicer defaults to the current year so the measure below should display YTD sales for 2022 (Jan 2022 to Sept 6, 2022).
I am using the USERELATIONSHIP function in the measure so that the sales date corresponds to the year slicer when I filter the page.
However, the measure that I am using returns $0 in sales. Any idea on how to correct this?
Prior Year YTD Sales =
VAR CurrentDate = TODAY()
VAR PreviousYearStartDate = DATE(YEAR(CurrentDate) - 1, 1, 1)
VAR CurrentYearStartDate = DATE(YEAR(CurrentDate), 1, 1)
RETURN COALESCE( CALCULATE( SUM(sales_table[total_sales]), FILTER( sales_table, sales_table[customer] <> "testcustomer" && sales_table[category] <> "testcategory" && sales_table[sales_date] >= PreviousYearStartDate && sales_table[sales_date] <= CurrentYearStartDate - 1 ), USERELATIONSHIP(sales_table[sales_date], 'date'[date]) ), 0 )
Hi @beepboop ,
Please try below measure and see if it works for you.
*replace the 'Table' to your TableName
LastYear YTD =
var maxdate= MONTH(TODAY())
var prioryear = SELECTEDVALUE('Table'[Year]) - 1
var result =
CALCULATE(
SUM('Table'[Value]),
FILTER(
ALL('Table'),
'Table'[Date].[MonthNo] <= maxdate && YEAR('Table'[Date]) = prioryear))
return result
I even tried this and it returns $0 for sales
Hello, how do I use my fact table and date table in the formula? Also, please see my comment here
Nevermind i solved it. I removed the userelationship function in my measure
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
11 | |
11 | |
10 | |
10 |
User | Count |
---|---|
19 | |
14 | |
13 | |
11 | |
8 |