cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
cnschulz
Helper IV
Helper IV

Fixed and filtered data in table

Hi, 

I have an interesting issue that I am sure is simple but it has broken my brain.

I am writing a report showing jobs assigned to crews on a weekly basis. It is used for forecasting availability and takes into account leave. I have two tables both using WEEKNUMBER and CREWID to classify data. Its working fine (see below) but not I need to introduce JOB PRIORITY as a filter and this breaks my mind.

WeekCrewJob HoursAvailable HoursBalance
202046A200220+20
202046B2202200
202046C250190-60

 

I need to introduce JOB PRIORITY to the JOB table and display the following table:

WeekCrewPriorityJob HoursAvailable HoursPriority BalanceOverall Balance
202046A1150220+70+20
202046A250220+170+20
202046B120220+2000
202046B2100220+1200
202046B3100220+1200
202046C11901900-60
202046C250190+140-60
202046C310190+180-60

 

So as you can see above, we should drop all priority 2 and 3 jobs for crew C or reallocate other staff. 

Next, we need to be able to filter on priority (ie "what if we did just priority 1 jobs?") The table should look like this:

 

WeekCrewPriorityJob HoursAvailable HoursPriority BalanceOverall Balance
202046A1150220+70+20
202046B120220+2000
202046C11901900-60

 

Then theres the possibility of selecting *multiple* priorites that I havent even considered yet!!

 

Can anyone offer any advice on creating this structute? Much appreciated. 🙂

 

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @cnschulz ,

First you can create a custom column [Priority] in power query for JOB table, the whole query is like this, close and apply it.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMjAxU9JRcgRiQ1MDpVgdNEF0MScgNsIiZmhAjKAzSNASiyC6NWCFQLFYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Week = _t, Crew = _t, #"Job Hours" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Week", Int64.Type}, {"Crew", type text}, {"Job Hours", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type",{"Crew"},{{"Rows", each Table.AddIndexColumn(_, "Index", 1), type table}}),
    #"Expanded Rows" = Table.ExpandTableColumn(#"Grouped Rows", "Rows", {"Week", "Job Hours", "Index"}, {"Week", "Job Hours", "Priority"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Expanded Rows",{"Week", "Crew", "Priority", "Job Hours"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"Week", Int64.Type}, {"Priority", Int64.Type}, {"Job Hours", Int64.Type}})
in
    #"Changed Type1"

JOB.png

Then create some calculated columns to get the expected output in JOB table:

Available Hours =
CALCULATE (
    SUM ( AVAILABILITY[Available Hours] ),
    FILTER ( ALL ( AVAILABILITY ), 'AVAILABILITY'[Crew] = EARLIER ( JOB[Crew] ) )
)

Priority Balance = [Available Hours] - [Job Hours]

Overall Balance =
[Available Hours]
    - CALCULATE (
        SUM ( JOB[Job Hours] ),
        FILTER ( ALL ( JOB ), 'JOB'[Crew] = EARLIER ( 'JOB'[Crew] ) )
    )

The final JOB table is like this:

pri.png

Filter priority 1:

p1.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yingjl
Community Support
Community Support

Hi @cnschulz ,

First you can create a custom column [Priority] in power query for JOB table, the whole query is like this, close and apply it.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMjAxU9JRcgRiQ1MDpVgdNEF0MScgNsIiZmhAjKAzSNASiyC6NWCFQLFYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Week = _t, Crew = _t, #"Job Hours" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Week", Int64.Type}, {"Crew", type text}, {"Job Hours", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type",{"Crew"},{{"Rows", each Table.AddIndexColumn(_, "Index", 1), type table}}),
    #"Expanded Rows" = Table.ExpandTableColumn(#"Grouped Rows", "Rows", {"Week", "Job Hours", "Index"}, {"Week", "Job Hours", "Priority"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Expanded Rows",{"Week", "Crew", "Priority", "Job Hours"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"Week", Int64.Type}, {"Priority", Int64.Type}, {"Job Hours", Int64.Type}})
in
    #"Changed Type1"

JOB.png

Then create some calculated columns to get the expected output in JOB table:

Available Hours =
CALCULATE (
    SUM ( AVAILABILITY[Available Hours] ),
    FILTER ( ALL ( AVAILABILITY ), 'AVAILABILITY'[Crew] = EARLIER ( JOB[Crew] ) )
)

Priority Balance = [Available Hours] - [Job Hours]

Overall Balance =
[Available Hours]
    - CALCULATE (
        SUM ( JOB[Job Hours] ),
        FILTER ( ALL ( JOB ), 'JOB'[Crew] = EARLIER ( 'JOB'[Crew] ) )
    )

The final JOB table is like this:

pri.png

Filter priority 1:

p1.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

PaulDBrown
Super User
Super User

@cnschulz 

How is the model set up?

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






JOB table contains 

WeekNumber, CrewId, JobHours 

 

AVAILABILITY table contains

WeekNumber, CrewId and HoursAvailable 

 

I now need to introduce Priority to the JOB table which will make a many to one relationship and break summarisation. 

 

 

Helpful resources

Announcements
Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Top Solution Authors
Top Kudoed Authors