Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
I need a list of the past 5 years in a new table, so the column would have (2013 ... 2016, 2017). List.Dates seems like the perfect function for this except the duration functions that it requires only have intervals of days/hrs/minutes as far as I can tell. Any way of doing this by way of formula instead of manually?
Thanks
Pierre
Solved! Go to Solution.
Hi @pierre415,
Based on my test, you should also be able to use the formula(DAX) below to create a new calculate table to make an automated list of past 5 years that updates itself over the years.
Year = DISTINCT ( SELECTCOLUMNS ( CALENDAR ( DATE ( YEAR ( TODAY () ) - 4, 1, 1 ), TODAY () ), "Year", YEAR ( [Date] ) ) )
Regards
@v-ljerr-msft @tamerj1
I have a similar query in which I need to get the list of latest 10 months in the column based on the dataset I have. I have date column and from there I have got startdate and end date. Based on this I was trying to get below result.
Suppose I have Start Date as 1st Sep'2018 and Last date 30th Sep'2021 from dataset. I want to fetch the data into another calculated field : 30th Sep'21 minus 10 months
Dec'2020
Jan'2021
Feb'2021
March'2021
April'2021......Sep'2021
And I need to use this as Slicer. It should be dynamic so that if next time I get data of Oct'2021 then period would change Jan'2021 - Oct 2021.....
Please help me on this.
@SK87
Please provide more information perhaps some screenshots along with sample data and expected output.
I want a slicer in which I can only see latest 10 months option in the dropdown based on date column in the dataset.
Date Month End | Date Report |
1/31/2019 | 1/1/2019 |
2/28/2019 | 2/1/2019 |
3/31/2019 | 3/1/2019 |
4/30/2019 | 4/1/2019 |
5/31/2019 | 5/1/2019 |
6/30/2019 | 6/1/2019 |
7/31/2019 | 7/1/2019 |
8/31/2019 | 8/1/2019 |
9/30/2019 | 9/1/2019 |
10/31/2019 | 10/1/2019 |
11/30/2019 | 11/1/2019 |
12/31/2019 | 12/1/2019 |
1/31/2020 | 1/1/2020 |
2/29/2020 | 2/1/2020 |
3/31/2020 | 3/1/2020 |
4/30/2020 | 4/1/2020 |
5/31/2020 | 5/1/2020 |
6/30/2020 | 6/1/2020 |
7/31/2020 | 7/1/2020 |
8/31/2020 | 8/1/2020 |
9/30/2020 | 9/1/2020 |
10/31/2020 | 10/1/2020 |
11/30/2020 | 11/1/2020 |
12/31/2020 | 12/1/2020 |
1/31/2021 | 1/1/2021 |
2/28/2021 | 2/1/2021 |
3/31/2021 | 3/1/2021 |
4/30/2021 | 4/1/2021 |
5/31/2021 | 5/1/2021 |
6/30/2021 | 6/1/2021 |
7/31/2021 | 7/1/2021 |
8/31/2021 | 8/1/2021 |
9/30/2021 | 9/1/2021 |
11/30/2018 | 11/1/2018 |
9/30/2018 | 9/1/2018 |
10/31/2018 | 10/1/2018 |
12/31/2018 | 12/1/2018 |
I have enddate from DAX:
Expected o/p in slicer:
Select Month
Dec'2020
Jan'2021
Feb'2021
March'2021
April'2021
May'2021
June'2021
July'2021
August'2021
Sepetember'2021
Hi @SK87
Please place this measure in the filter pane of the slicer
Filter Measure =
VAR LastMonth = CALCULATE ( MAX ( Data[Date Month End] ), REMOVEFILTERS ( ) )
VAR FirstMonth = EOMONTH ( LastMonth, -10 )
VAR FilteredMonths =
FILTER (
VALUES ( Data[Date Month End] ),
Data[Date Month End] >= FirstMonth
&& Data[Date Month End] < LastMonth
)
RETURN
COUNTROWS ( FilteredMonths )
For something this straightforward, you can manually create a table. Simply click on "Enter Data" on the top ribbon of Power Bi and it will allow you to manually enter a small dataset like this.
If you want/need something fancier without getting into utilizing complex M functions (M is great but sometimes the heavy lifting is better off being done by the big boys such as Chris Webb instead of mere mortals like us), you can use the "New Table" functionality that is in Power BI. So for example, if the data you need for a look up table is contained within your fact table, you could create a dynamic table by using some of the "table" functions of DAX. So in this case, if all 5 years you need are con[tained in your fact table, you can simply do the following:
1. Select "modeling" tab
2. Select "New Table"
3. In formula bar, create new table with following syntax:
Year Table = ALL('FACT_TABLE_NAME'[YEAR])
That's it. If you want more details on the create table functionality, there's a great blog post by @MattAllington (whom you will see frequently posting on this forum and all around the web on the Microsoft BI Stack) on PowerPivotPro here: Table Function
Whew, that's a lot. I hope this helps. Good luck.
Thanks, I'm looking to make an automated list that updates itself over the years though
Hi @pierre415,
Based on my test, you should also be able to use the formula(DAX) below to create a new calculate table to make an automated list of past 5 years that updates itself over the years.
Year = DISTINCT ( SELECTCOLUMNS ( CALENDAR ( DATE ( YEAR ( TODAY () ) - 4, 1, 1 ), TODAY () ), "Year", YEAR ( [Date] ) ) )
Regards
That's awesome, thank you
Hi,
I was struggling with the same issue, so this helped me a lot. The only thing I can't get to work is that I would like to have the number of years to "look back" based on a parameter that can be input. The provided solution does not seem to allow to use a input parameter for the calculation of the start date year. 😫
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
103 | |
99 | |
98 | |
38 | |
37 |
User | Count |
---|---|
151 | |
121 | |
73 | |
71 | |
63 |