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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Super User
Super User

@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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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