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
Anonymous
Not applicable

Weekly data converted into daily data based on phased targets

I have a dataset that updates weekly, in power query editor and I have a table that I want to use with that data to tell me if the orders fulfilled are performing against target. I can't see a way of doing this without it repeating the data for each day (so i end up with 5x the orders for Mon-Fri which isn't correct) but is it possible to base the split of the data on the table that gives me a target for orders fulfilled which has a daily target (see second table below)?

I have a date table too, so have the start date of the week etc. but if i merge this with my dataset, it just maps my 'Mon-Fri' from the target table against every date. I feel like i'm missing something obvious here; is there a way to add in dates and days without repeating the data? At this point, i'd accept it splitting the orders by 20% for each date because then maybe I could fix it later on??

 

DATASETORDERS PLACEDORDERS FULFILLEDORDERS PLACEDORDERS FULFILLEDORDERS PLACEDORDERS FULFILLED
FISCAL WEEK112233
DATE27/02/202327/02/202306/03/202306/03/202313/03/202313/03/2023
PLANT A202020202020
PLANT B201510202015
PLANT C302520303025

 

 

TARGETSMONTUESWEDTHURSFRI
PLANT A0.50.670.830.940.99
PLANT B0.50.750.90.991
PLANT C0.30.60.80.991
3 REPLIES 3
KNP
Super User
Super User

Excel version of the Power BI file attached.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
Anonymous
Not applicable

Hi, thank you for responding- I can't download the pbix as I don't have power bi on my work laptop and IT won't let me download it; I am using power query editor for excel files. The data I provided is dummy data and I have already unpivoted the actual data needed in my work, I have provided some of my code below, but I may be coming at it wrong and haven't explained myself well.

 

let
Source = Csv.Document(File.Contents("C:\Users\OneDrive - y\Documents\Consumption Week Project\BI Weekly Demand Extract.csv"),[Delimiter="=", Columns=1, Encoding=1252, QuoteStyle=QuoteStyle.Csv]),
RefPoint = Source,
#"Added Index" = Table.AddIndexColumn(RefPoint, "Index", 1, 1, Int64.Type),
#"Filtered Rows" = Table.SelectRows(#"Added Index", each Text.StartsWith([Column1], "Fiscal year/period")),
Index = #"Filtered Rows"{0}[Index],
Custom1 = RefPoint,
#"Removed Top Rows" = Table.Skip(Custom1,Index-1),
#"Replaced Value" = Table.ReplaceValue(#"Removed Top Rows","""","",Replacer.ReplaceText,{"Column1"}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Replaced Value", "Column1", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Column1.1", "Column1.2", "Column1.3", "Column1.4", "Column1.5", "Column1.6", "Column1.7", "Column1.8", "Column1.9", "Column1.10", "Column1.11"}),
#"Promoted Headers" = Table.PromoteHeaders(#"Split Column by Delimiter", [PromoteAllScalars=true]),
#"Replaced Value1" = Table.ReplaceValue(#"Promoted Headers",",","",Replacer.ReplaceText,{",,"}),
#"Renamed Columns" = Table.RenameColumns(#"Replaced Value1",{{",,", "HL"}, {"", "Value Type"}}),
#"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"_3", "Column11"}),
#"Added Custom" = Table.AddColumn(#"Removed Columns", "Fiscal Week", each Date.StartOfWeek
(Date.AddWeeks
(#date(Number.FromText(Text.End([#"Fiscal year/period"],4)), 1, 1),
Number.FromText([Fiscal WW])-1), Day.Monday)),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Fiscal Month", each #date(
Number.FromText(Text.End([#"Fiscal year/period"],4)),
Number.FromText(Text.Start([#"Fiscal year/period"],3)),
1)),
#"Filtered Rows1" = Table.SelectRows(#"Added Custom1", each true),
#"Added Custom2" = Table.AddColumn(#"Filtered Rows1", "Month", each Date.MonthName(
#date(2000,
Number.FromText(
Text.Start([#"Fiscal year/period"],3) ), 1)
,"MMMM")),
#"Changed Type" = Table.TransformColumnTypes(#"Added Custom2",{{"HL", type number}, {"Fiscal Week", type date}, {"Fiscal Month", type date}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[#"Value Type"]), "Value Type", "HL", List.Sum),
#"Replaced Value6" = Table.ReplaceValue(#"Pivoted Column","Impulse","Off Premise",Replacer.ReplaceText,{"Sales Office_1"}),
#"Merged Queries1" = Table.NestedJoin(#"Replaced Value6", {"Sales Office_1"}, SalesOffPhase, {"Sales Office Desc"}, "SalesOffPhase", JoinKind.LeftOuter),
#"Expanded SalesOffPhase" = Table.ExpandTableColumn(#"Merged Queries1", "SalesOffPhase", {"Phase Day", "Target Consumption"}, {"Phase Day", "Target Consumption"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded SalesOffPhase",{{"Plant", Int64.Type}}),

KNP
Super User
Super User

Firstly, you should avoid having your data in this layout and if this is how you get it, then I'd suggest unpivoting.

Unpivoting multiple rows like this can be complex, thankfully people like Bill Szysz and @ImkeF are in the community and have simplified it for us. 

 

(below code taken from the end of this post, https://www.thebiccountant.com/2017/06/19/unpivot-by-number-of-columns-and-rows-in-powerbi-and-power...)

 

let
    Source = (t as table, FirstNColumnsToKeep as number, FirstNRowsToSkip as number)=>


let
// ------------------------------------------------------------------------------------------------------------------------
// This part creates a fake, one row table with column names like in original table  ( first row (the only row) will be promoted later )

            Tab = Table.FirstN(t, FirstNRowsToSkip),
            Custom1 = Table.Transpose(Tab),
            ChangedType = Table.TransformColumnTypes(Custom1,List.Transform(Table.ColumnNames(Custom1), each {_, type text})),
            AllColumnNames = Table.ColumnNames(Tab),
            ConstColumnNames = List.FirstN(AllColumnNames,FirstNColumnsToKeep),
            ListOfTransposedColumnNames = Table.ColumnNames(ChangedType),

//             ------------------------------------
// The line below is not necessary if null is real null value and not "null" (like in Table1)


            #"Replaced Value" = Table.ReplaceValue(ChangedType,"null",null,Replacer.ReplaceValue, ListOfTransposedColumnNames),

//             -----------------------------------

            ReadyToMerge = Table.FillDown(#"Replaced Value", ListOfTransposedColumnNames),
            #"Merged Columns" = Table.CombineColumns(ReadyToMerge, ListOfTransposedColumnNames, Combiner.CombineTextByDelimiter("$_$", QuoteStyle.None),"MergedColumns"),
            #"Filtered Rows" = Table.Skip(#"Merged Columns", FirstNColumnsToKeep)[MergedColumns],
            AllNewNames = Table.FromRows({ConstColumnNames & #"Filtered Rows"}, AllColumnNames),
// -------------------------------------------------------------------------------------------------------------------------

// This part combines fake table (AllNewNames) and original table (t) without FirstNRowsToSkip and then it does a few (easy) necessary things

    Combine = Table.Combine( {AllNewNames, Table.Skip(t, FirstNRowsToSkip)}),
    #"Promoted Headers" = Table.PromoteHeaders(Combine, [PromoteAllScalars=true]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", ConstColumnNames, "Attrib", "Value"),
    ListOfSplitedColumnNames = List.Transform({1..FirstNRowsToSkip}, each "Attrib." & Text.From(_) ),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns","Attrib",Splitter.SplitTextByDelimiter("$_$", QuoteStyle.Csv),ListOfSplitedColumnNames),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter", List.Transform(ListOfSplitedColumnNames, each {_, type text}))
in
    #"Changed Type"

// Documentation ( I've stolen this part from You Imke;-))	
	, documentation = [
Documentation.Name =  " fxUnpivBill
", Documentation.Description = " Unpivots a table according to the number of columns and header rows passed on in the parameters
" , Documentation.LongDescription = " Unpivots a table according to the number of columns and header rows passed on in the parameters
", Documentation.Category = " Table functions
", Documentation.Source = " local
", Documentation.Author = " Bill Szysz
", Documentation.Examples = {[Description =  " 
" , Code = " Look at the code in Advanced Editor to read some notes
 I've stolen this part (Documentation part) from You Imke ;-)
 ", Result = " 
"]}] 
 in 
  Value.ReplaceType(Source, Value.ReplaceMetadata(Value.Type(Source), documentation))

 

If you create a blank query and copy and paste this into the advanced editor, you'll have an easy way to get your data in a better format.

 

See attached PBIX, if it helps you. Important to demote the headers first before running the table through the function.

 

I have made changes in the attached PBIX (see Output table) that is in line with what I think you're trying to achieve, but have a look and let me know.

 

 

 

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

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
Top Kudoed Authors