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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
PSdhillon
Frequent Visitor

M query help to generate data table with hourly rows in addition to existing table

Hi, 

 

I have got below data as shown in image

data format.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

To get above datatable, i have used below query

 

let
    TodaysDate = Date.From(DateTimeZone.FixedUtcNow()),
    Ranges = {
                {"1D", 
                TodaysDate, 
                TodaysDate, 
                1},
                {"WTD", 
                Date.From(Date.StartOfWeek(TodaysDate)), 
                TodaysDate, 
                2},
                {"MTD", 
                Date.From(Date.StartOfMonth(TodaysDate)), 
                TodaysDate, 
                3},
                {"QTD",
                Date.From(Date.StartOfQuarter(TodaysDate)),
                TodaysDate,
                 4},     
                {"YTD", 
                Date.From(Date.StartOfYear(TodaysDate)), 
                TodaysDate, 
                5},
                {"1W", 
                Date.AddWeeks(TodaysDate,-1) + #duration(1,0,0,0), 
                TodaysDate, 
                6},
                {"4W", 
                Date.AddMonths(TodaysDate,-1) + #duration(1,0,0,0), 
                TodaysDate, 
                7},
                {"LY", 
                Date.AddYears(TodaysDate,-1) + #duration(1,0,0,0), 
                TodaysDate, 
                8}
             },
    GetTables = List.Transform(Ranges, 
            each CreatePeriodTable(_{0}, _{1}, _{2}, _{3})),
    Output = Table.Combine(GetTables)
in
    Output

 

Now the question, i have is i want to generate the file including all the hours starting form the first date in datatable. Similarly, the fist column must state whether it is part of 1D (one day) group, 1W (1 week) group & Month to date (MTD) , quarter to date QTD & year to date (YTD). I am using this to ultimately create a time slicer tile, based on which dashboard user will select the time. Another slicer which is not part of the details which i shared, will actually do the aggregation of the data, e.g day, week, month etc. I managed to get this sorted, but what i missed is Hour part, For single day selection, user want to see the data in hourly, which in current datatable wont possible, 

Please help/guide me generate code in M query where the table contain 24 rows for every date & every group, so that i can club it when required. Hope i managed to explain my problem statement well. TIA

2 REPLIES 2
ImkeF
Community Champion
Community Champion

Sorry, but I don't understand what you're after here. Could you please paste a link to a sample file with a sample of the desired input and output you're after? Also please paste code for function "CreatePerdiodTable".

Thanks.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Greg_Deckler
Community Champion
Community Champion

@ImkeF 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.