Forum Discussion
How to get selected month from date table
Hi Experts ,
i want create a dax function for selected month date
above pic is sample data
Requiremnt
if i select filter as year 2022 dax fucntion (Dateselected month) should be like as 01-05-2022
output like below
Hi Mahamood0218 ,
If your date is always the first of May on the year that you select, then the DAX for your card display would be something like this:
_selectionStartDate = VAR __year = SELECTEDVALUE(calendar[year]) RETURN FORMAT( DATE(__year, 05, 01), "dd-MM-yyyy" )Pete
Hi Mahamood0218 ,
No, the month in this example is fixed, it's only the year that is dynamic based on the selected slicer value.
If you want it to always default to the first of the current month, then you would use something like this:
_DateSelectedMonthStart = VAR __year = SELECTEDVALUE(DimDate[Year]) VAR __month = MONTH(TODAY()) RETURN FORMAT( DATE(__year, __month, 01), "dd-MM-yyyy" )Pete
3 Replies
- BA_PeteSuper User
Hi Mahamood0218 ,
If your date is always the first of May on the year that you select, then the DAX for your card display would be something like this:
_selectionStartDate = VAR __year = SELECTEDVALUE(calendar[year]) RETURN FORMAT( DATE(__year, 05, 01), "dd-MM-yyyy" )Pete
- Mahamood0218Helper II
Hi BA_Pete ,
Thanks for shared the code i have applied above code now it is working,
Note: I have another question in your code you had directly mentioned in DATE(Year,05,01) means month as mentioned directly ''05'' if i will login the same pbi report next month my dax function "DateSelectedMonthstart2" will shows like ''01-06-2022''?
- BA_PeteSuper User
Hi Mahamood0218 ,
No, the month in this example is fixed, it's only the year that is dynamic based on the selected slicer value.
If you want it to always default to the first of the current month, then you would use something like this:
_DateSelectedMonthStart = VAR __year = SELECTEDVALUE(DimDate[Year]) VAR __month = MONTH(TODAY()) RETURN FORMAT( DATE(__year, __month, 01), "dd-MM-yyyy" )Pete