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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Ryukatan10
Regular Visitor

Considering Specific Days Between Two Dates

Hello everyone, I'm stuck with this issue and don't know how to solve it.

 

I have a database that show several rows like this one:

 

FlightAcftMonTueWedThuFriSatSunBegin OperationEnd Operation
5467C208000000705/01/202206/27/2022

 

In this case, I have a flight registration that will ocurr from 05/01/2022 to 06/27/2022, only at Sunday, because all the others weekday are "0" in this row.

 

I would like that Power BI shows or undertand something like that:

 

FlightDate
546705/01/2022
546705/08/2022
546705/15/2022
546705/22/2022
546705/29/2022
546706/05/2022
546706/12/2022
546706/19/2022
546706/26/2022

 

I already have another table with dates in one column and weekday in number from 1 to 7 in other column, but even if I create a relationship with al the seven columns form the flights database with this table of dates, it not work in the way that i want.

 

Can Anyone Help Me?

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @Ryukatan10 ,

 

Here a possible solution:

tomfox_0-1650140944443.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjUxM1fSUXI2MrAAUgY4MEiJgaG+gam+kYGREZBjZK5vYAbhxMYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Flight = _t, Acft = _t, Mon = _t, Tue = _t, Wed = _t, Thu = _t, Fri = _t, Sat = _t, Sun = _t, #"Begin Operation" = _t, #"End Operation" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Flight", Int64.Type}, {"Acft", type text}, {"Mon", Int64.Type}, {"Tue", Int64.Type}, {"Wed", Int64.Type}, {"Thu", Int64.Type}, {"Fri", Int64.Type}, {"Sat", Int64.Type}, {"Sun", Int64.Type}, {"Begin Operation", type date}, {"End Operation", type date}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Flight", "Acft", "Begin Operation", "End Operation"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each [Value] <> 0),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom", each { Number.From([Begin Operation])..Number.From([End Operation]) }),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Custom", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom.1", each if Text.Start ( Date.DayOfWeekName([Custom], "en-US"), 3) = [Attribute] then 1 else null),
    #"Filtered Rows1" = Table.SelectRows(#"Added Custom1", each ([Custom.1] = 1)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"Acft", "Begin Operation", "End Operation", "Attribute", "Value", "Custom.1"})
in
    #"Removed Columns"

 

I did even an unpivoting on your day columns which was not necessarily needed to fix the example above. However, I hope with that it even works with other rows in your data. I.e. with flights that occurr on multiple days in a week etc. Not sure, whether this one here will be the final solution, but I think we got a step closer.

 

Let me know if it works out and come back if you have questions 🙂 Also, feel free to share some more data if you need more help.

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

2 REPLIES 2
Ryukatan10
Regular Visitor

@tackytechtom Perfect Man

 

I had to make some changes but the core problem was solved with your solution, thanks a lot

tackytechtom
Super User
Super User

Hi @Ryukatan10 ,

 

Here a possible solution:

tomfox_0-1650140944443.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjUxM1fSUXI2MrAAUgY4MEiJgaG+gam+kYGREZBjZK5vYAbhxMYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Flight = _t, Acft = _t, Mon = _t, Tue = _t, Wed = _t, Thu = _t, Fri = _t, Sat = _t, Sun = _t, #"Begin Operation" = _t, #"End Operation" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Flight", Int64.Type}, {"Acft", type text}, {"Mon", Int64.Type}, {"Tue", Int64.Type}, {"Wed", Int64.Type}, {"Thu", Int64.Type}, {"Fri", Int64.Type}, {"Sat", Int64.Type}, {"Sun", Int64.Type}, {"Begin Operation", type date}, {"End Operation", type date}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Flight", "Acft", "Begin Operation", "End Operation"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each [Value] <> 0),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom", each { Number.From([Begin Operation])..Number.From([End Operation]) }),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Custom", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom.1", each if Text.Start ( Date.DayOfWeekName([Custom], "en-US"), 3) = [Attribute] then 1 else null),
    #"Filtered Rows1" = Table.SelectRows(#"Added Custom1", each ([Custom.1] = 1)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"Acft", "Begin Operation", "End Operation", "Attribute", "Value", "Custom.1"})
in
    #"Removed Columns"

 

I did even an unpivoting on your day columns which was not necessarily needed to fix the example above. However, I hope with that it even works with other rows in your data. I.e. with flights that occurr on multiple days in a week etc. Not sure, whether this one here will be the final solution, but I think we got a step closer.

 

Let me know if it works out and come back if you have questions 🙂 Also, feel free to share some more data if you need more help.

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors