Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
lawada
Helper III
Helper III

calculate data for weekdays in future date

in our business we have a feature that lets users book a timeslot and weekday to recieve their service (weekly or BiWeekly) , for example ,user X booked his service to be  Friday 10:00 AM Weekly , user Y has booked his service to be every Tuesday 1:00 PM  BiWeekly

So user X will recieve his service Friday 10:00AM (Every Week),  and user Y will recieve his serive Tuesday 1:00 PM (Every Two Weeks)

 

the request is :

create a matrix for every future date that shows how many users have booked a specific timeslot , ex:

 

 tuesady 07-06-2021Wednesday 07-07-2021Thursday  07-08-2021Friday  07-09-2021Saturday  07-10-2021Sunday 07-11-2021Monday 07-12-2021tuesady 07-13-2021Wednesday 07-14-2021Thursday  07-15-2021Friday  07-16-2021Saturday  07-17-2021Sunday 07-18-2021Monday 07-19-2021tuesady 07-20-2021Wednesday 07-21-2021Thursday  07-22-2021Friday  07-23-2021   
10:00 AM   1 User      1 User      1 users   
11:00 AM                     
12:00 PM                     
1:00 PM1 User

 

 

 

            1 User      

 

so as you can see , dates are in the futute , and do not exist in our database ,

the data i have is :
-User ID
-weekday
-time
-service date ( data will be shown once service date has passed , if the date hasnt come yet , data will be NULL)

 

ex for the table :

User IDWeek dayTimeSerive datefrequency
124Tusday6:00 PM6/27/2021weekly
567Friday11:00 AMNULLweekly
566Sunday4:00 PMNULLbiweekly
433Friday3:00 PMNULLbiweekly

 

so how can i count total users who booked a service each weekday (weekly/biweekly) for dates in the futute?

9 REPLIES 9
ERD
Super User
Super User

Hi @lawada , what is the starting date for biweekly frequency case ?

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

it's like a calender , assume it starts from today , if a  user have a biweekly frequency evey tuesday  10:00 AM then this user should be counted on tuesdy  07/13/2021 10:00 AM -  07/27/2021 10:00 AM- 08/10/2021 10:00 AM and so on .

@lawada ,

You need to have Date and Time tables.

I don't know how your real data looks like and if your example table is with the same columns as in the real scenario, so I'm not sure if it's the best approach in your case, but you can try to play with this measure:

Measure = 
VAR frequency = MAX ( T[frequency] )
VAR countUsers =
    CALCULATE (
        DISTINCTCOUNT ( T[User ID] ),
        CROSSFILTER ( 'Weekday'[Day Name], 'Date'[Day Name], BOTH ),
        CROSSFILTER ( T[Week day], 'Weekday'[Day Name], BOTH )
    )
RETURN
    SWITCH (
        TRUE (),
        frequency = "weekly", countUsers,
        frequency = "biweekly", IF ( ISEVEN ( MAX ( 'Date'[Week of Year] ) ), "", countUsers ),
        ""
    )

ERD_0-1626165154820.png

ERD_1-1626165967847.png

ERD_2-1626166014059.png

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

i noticed that you created a 1:1 relationship between time table and Tl6 table , however, in the data source table the time is not a unique key ,many users can have similar timimgs , so relationship in this case would be 1:* 

@lawada ,

Concerning 1:* relationship with Time table - it's ok. It's 1:1 here due to the data itself.

I cannot share the file, but I can share the PQ scripts:

1) Time

 

let
    Source = List.Times(#time(0,0,0),24*60*60,#duration(0,0,0,1)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Time"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Time", type time}}),
    #"Inserted Start of Hour" = Table.AddColumn(#"Changed Type", "Start of Hour", each Time.StartOfHour([Time]), type time)
in
    #"Inserted Start of Hour"

 

2) Date

 

let
    Today=Date.From(DateTime.LocalNow()), // today's date
    FromYear = 2020, // set the start year of the date dimension. dates start from 1st of January of this year
    ToYear=2022, // set the end year of the date dimension. dates end at 31st of December of this year
    FromDate=#date(FromYear,1,1),
    ToDate=#date(ToYear,12,31),
    Source=List.Dates(
        FromDate,
        Duration.Days(ToDate-FromDate)+1,
        #duration(1,0,0,0)
    ),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}}),
    #"Inserted Year" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([Date]), Int64.Type),
    #"Inserted Month" = Table.AddColumn(#"Inserted Year", "Month", each Date.Month([Date]), Int64.Type),
    #"Inserted Day Name" = Table.AddColumn(#"Inserted Month", "Day Name", each Date.DayOfWeekName([Date]), type text),
    #"Inserted Day of Week" = Table.AddColumn(#"Inserted Day Name", "Day of Week", each Date.DayOfWeek([Date]), Int64.Type),
    #"Inserted Month Name" = Table.AddColumn(#"Inserted Day of Week", "Month Name", each Date.MonthName([Date]), type text),
    #"Added Custom4" = Table.AddColumn(#"Inserted Month Name", "Month Year", each Text.Start([Month Name], 3) & "-" & Text.End(Text.From([Year]),2)),
    #"Inserted Week of Year" = Table.AddColumn(#"Added Custom4", "Week of Year", each Date.WeekOfYear([Date]), Int64.Type)
in
    #"Inserted Week of Year"

 

3) Weekday

ERD_0-1626185656352.png

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Thank you for sharing the PQ codes! but one doubt is , how did you create the coloumn 

'Date'[Week of Year]

since it's not added inside the date table , and can you please explain how does this line work in the measure you created ?

 frequency = "biweekly", IF ( ISEVEN ( MAX ( 'Date'[Week of Year] ) ), "", countUsers ),

@lawada , please, check again the script. I've added the last line of code.

Details: 

ERD_0-1626260576640.png

Since you wanted to start calculation from today, I've looked and current week number - if it is even or not. And then just used https://dax.guide/iseven/ function to count values bi-weekly.

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

thank you so much for the help , i used the exact same steps in my data model , however dax  code didnt give same result , played around and made some changes in the data model and dax and its working now

can i have the power bi file please? or can you share the dax code you created for Time table, Date table ,and Weekday table. thank you in advance..

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors