The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
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
Solved! Go to Solution.
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
Proud to be a Datanaut!
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
Proud to be a Datanaut!
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
Proud to be a Datanaut!
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''?
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
Proud to be a Datanaut!