Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
I am stuck in one of the scenario of power bi. I am using Table visual to show weekday name, first date, last date as per below.
User can select custom date range(for example I have selected 1st July 2022 to 31st July 2022) and this will be filters on all pages. Also there is one calculated column which will describe whether its weekday or weekend, used as hidden slicer with weekday as default value.
Its showing 29th July as LastDate in above visual considering 31st july as Sunday. I want to show 31st july as last day irrespective of selected slicer value.
Measures:
FirstDate = FIRSTDATE(ALLSELECTED('Calender Dates'[Date]))
LastDate = LASTDATE(ALLSELECTED('Calender Dates'[Date]))
Slicers: IsCalDayWeekDayOrWeekend(calculated column which will consider Mon to Fri as weekday. Sat and Sun as weekend). Default selected as weekday.
I have tried ALL, ALLEXCEPT but it did not give right results. Please suggest and Thanks In Advance.
Hi @daXtreme
I have tried the suggested DAX, seems its not giving correct result.
I have selected date range as 1st Oct 2022 to 16th Oct 2022. Also slicer selected as "Weekday". I am expecting first date 1st Oct 2022 and Last Date as 16th Oct 2022 for all the weekday.
Unfortunately i am not able to upload sample file, but i have created calendar table with below dax and suggested dax.
Appreciated your help on this.
Thanks.
You have to clearly define the logic behind your thinking and give good examples.
Hi @daXtreme
Thank you for your reply.
Could you please download sample file from below link.
https://drive.google.com/file/d/17SxTofrDMijXZqxUdrWMSlloFNLcXouU/view?usp=sharing
There is one table visual which will require Weekday name, first date, and last date. User can select any period which is available under filters on all pages section. To show only weekdays i have selected only Weekday under one slicer and plan is we will hide it through selection pane. Now problem is if first date or last date from the selected period lies on saturday or sunday the on visual first date or last date consider as Friday, however user have selected sat and sun in period so it should consider for first date or last date.
Thanks.
OK, this is what your date table should look like:
And here are the two measures you're after:
FirstDate v2 =
var MinWeekID =
CALCULATE(
MIN( T[WeekID] ),
ALLSELECTED( T )
)
var Output =
CALCULATE(
MIN( T[Date] ),
T[WeekID] = MinWeekID,
REMOVEFILTERS( T )
)
return
Output
and
LastDate v2 =
var MaxWeekID =
CALCULATE(
MAX( T[WeekID] ),
ALLSELECTED( T )
)
var Output =
CALCULATE(
MAX( T[Date] ),
T[WeekID] = MaxWeekID,
REMOVEFILTERS( T )
)
return
Output
Hi,
This part should cause the behaviour you described: "IsCalDayWeekDayOrWeekend(calculated column which will consider Mon to Fri as weekday. Sat and Sun as weekend). Default selected as weekday."
ALLSELECTED will apply the weekday filter to the lastdate and remove the weekend from the range.
Try something like this:
This way the filter context should be correct.
I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!
My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/
Proud to be a Super User!
Hi ValtteriN,
Thank you for your reply. I have tried this, unfortunately its not giving the expected output.
Try this one:
LastDate =
CALCULATE(
MAX( 'Calender Dates'[Date] ),
REMOVEFILTERS( 'Calender Dates'[IsCalDayWeekDayOrWeekend] ),
ALLSELECTED( 'Calender Dates' )
)
Hi daXtreme,
Thanks for your reply, i have tried the suggestion, however now it takes weekdayname in context and gives the last date respective to week day name.
Thanks.
User | Count |
---|---|
57 | |
21 | |
19 | |
16 | |
16 |
User | Count |
---|---|
86 | |
77 | |
52 | |
37 | |
22 |