Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
Dear All,
I have a table with three columns:
Cost
Start Date
End Date
I need to get to a table/matrix view where I show the Cost divided for (End Date - Start Date) with a DAY granularity.
My Table:
My desired result:
Any idea?
Thanks a lot
Solved! Go to Solution.
Hi @LoryMenCR
I have created a power query solution for this. Check the attached file or use below m code.
let
Source = Table,
Custom1 = Table.AddColumn(
Source,
"Granularity",
each
let
DayCount = Duration.Days(Duration.From([End Date] - [Start Date]))+1,
DayOffsetList = {0..DayCount},
CostList = List.Repeat({[Cost] / DayCount}, DayCount),
DateList = List.Dates([Start Date], DayCount, #duration(1,0,0,0)),
YearList = List.Transform(DateList, each Date.MonthName(_)&"-"&Text.From(Date.Year(_)))
in
Table.FromColumns(
{DateList,YearList, CostList},
{"Date", "MonthYear", "Cost"}
)
),
ExpandedGranularity = Table.ExpandTableColumn(Custom1, "Granularity", {"Date", "MonthYear", "Cost"}, {"Granularity.Date", "Granularity.MonthYear", "Granularity.Cost"}),
GroupedRows = Table.Group(ExpandedGranularity, {"Granularity.MonthYear"}, {{"Cost", each List.Sum([Granularity.Cost]), type number}})
in
GroupedRows
Above numbers are the accurate numbers if split on days.
If this post helps, then please consider Accept it as the solution to help the others find it more quickly. Appreciate you kudos!!
Follow me on LinkedIn!!!
Hi @LoryMenCR ,
If you don't want to transform your data in Power Query Editor, you can try Dax to create a measure.
We need to add a DimDate table to help calculation.
DimDate = ADDCOLUMNS(CALENDARAUTO(),"Year",YEAR([Date]),"Month",MONTH([Date]),"YearMonth",FORMAT([Date],"MMM-YYYY"),"YearMonthSort",YEAR([Date])*100+MONTH([Date]))
Measure:
Measure =
VAR _Virtual =
GENERATE ( 'Table', CALENDAR ( 'Table'[Start Date] + 1, 'Table'[End Date] ) )
VAR _ADDCOLUMNS =
ADDCOLUMNS ( _Virtual, "Datediff1", DATEDIFF ( [Start Date], [End Date], DAY ) )
RETURN
SUMX (
FILTER (
_ADDCOLUMNS,
[Date] >= MIN ( DimDate[Date] )
&& [Date] <= MAX ( DimDate[Date] )
),
DIVIDE ( [Cost], [Datediff1] )
)
Result is as below.
If you want to use Power Query, NaveenGandhi's workaround is a good way, you just need to do some update on it.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFDSUTIyMDLRNzAEIjjHSN/AQilWJ1rJ2ARFiaEpkhIjiBJTJBVGaIYYK8XGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Cost = _t, #"Start Date" = _t, #"End Date" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Cost", Int64.Type}, {"Start Date", type date}, {"End Date", type date}}),
Custom1 = Table.AddColumn(#"Changed Type", "Granularity", each let
DayCount = Duration.Days(Duration.From([End Date] - [Start Date])),
DayOffsetList = {0..DayCount},
CostList = List.Repeat({[Cost] / DayCount}, DayCount),
DateList = List.Dates(Date.AddDays([Start Date],1), DayCount, #duration(1,0,0,0)),
YearList = List.Transform(DateList, each Date.MonthName(_)&"-"&Text.From(Date.Year(_)))
in
Table.FromColumns(
{DateList,YearList, CostList},
{"Date", "MonthYear", "Cost"}
)),
#"Expanded Granularity" = Table.ExpandTableColumn(Custom1, "Granularity", {"Date", "MonthYear", "Cost"}, {"Date", "MonthYear", "Cost.1"}),
#"Grouped Rows" = Table.Group(#"Expanded Granularity", {"MonthYear"}, {{"Count", each List.Sum([Cost.1]), type number}})
in
#"Grouped Rows"
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @LoryMenCR ,
If you don't want to transform your data in Power Query Editor, you can try Dax to create a measure.
We need to add a DimDate table to help calculation.
DimDate = ADDCOLUMNS(CALENDARAUTO(),"Year",YEAR([Date]),"Month",MONTH([Date]),"YearMonth",FORMAT([Date],"MMM-YYYY"),"YearMonthSort",YEAR([Date])*100+MONTH([Date]))
Measure:
Measure =
VAR _Virtual =
GENERATE ( 'Table', CALENDAR ( 'Table'[Start Date] + 1, 'Table'[End Date] ) )
VAR _ADDCOLUMNS =
ADDCOLUMNS ( _Virtual, "Datediff1", DATEDIFF ( [Start Date], [End Date], DAY ) )
RETURN
SUMX (
FILTER (
_ADDCOLUMNS,
[Date] >= MIN ( DimDate[Date] )
&& [Date] <= MAX ( DimDate[Date] )
),
DIVIDE ( [Cost], [Datediff1] )
)
Result is as below.
If you want to use Power Query, NaveenGandhi's workaround is a good way, you just need to do some update on it.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFDSUTIyMDLRNzAEIjjHSN/AQilWJ1rJ2ARFiaEpkhIjiBJTJBVGaIYYK8XGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Cost = _t, #"Start Date" = _t, #"End Date" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Cost", Int64.Type}, {"Start Date", type date}, {"End Date", type date}}),
Custom1 = Table.AddColumn(#"Changed Type", "Granularity", each let
DayCount = Duration.Days(Duration.From([End Date] - [Start Date])),
DayOffsetList = {0..DayCount},
CostList = List.Repeat({[Cost] / DayCount}, DayCount),
DateList = List.Dates(Date.AddDays([Start Date],1), DayCount, #duration(1,0,0,0)),
YearList = List.Transform(DateList, each Date.MonthName(_)&"-"&Text.From(Date.Year(_)))
in
Table.FromColumns(
{DateList,YearList, CostList},
{"Date", "MonthYear", "Cost"}
)),
#"Expanded Granularity" = Table.ExpandTableColumn(Custom1, "Granularity", {"Date", "MonthYear", "Cost"}, {"Date", "MonthYear", "Cost.1"}),
#"Grouped Rows" = Table.Group(#"Expanded Granularity", {"MonthYear"}, {{"Count", each List.Sum([Cost.1]), type number}})
in
#"Grouped Rows"
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @LoryMenCR
I have created a power query solution for this. Check the attached file or use below m code.
let
Source = Table,
Custom1 = Table.AddColumn(
Source,
"Granularity",
each
let
DayCount = Duration.Days(Duration.From([End Date] - [Start Date]))+1,
DayOffsetList = {0..DayCount},
CostList = List.Repeat({[Cost] / DayCount}, DayCount),
DateList = List.Dates([Start Date], DayCount, #duration(1,0,0,0)),
YearList = List.Transform(DateList, each Date.MonthName(_)&"-"&Text.From(Date.Year(_)))
in
Table.FromColumns(
{DateList,YearList, CostList},
{"Date", "MonthYear", "Cost"}
)
),
ExpandedGranularity = Table.ExpandTableColumn(Custom1, "Granularity", {"Date", "MonthYear", "Cost"}, {"Granularity.Date", "Granularity.MonthYear", "Granularity.Cost"}),
GroupedRows = Table.Group(ExpandedGranularity, {"Granularity.MonthYear"}, {{"Cost", each List.Sum([Granularity.Cost]), type number}})
in
GroupedRows
Above numbers are the accurate numbers if split on days.
If this post helps, then please consider Accept it as the solution to help the others find it more quickly. Appreciate you kudos!!
Follow me on LinkedIn!!!
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 48 | |
| 40 | |
| 38 | |
| 20 | |
| 16 |
| User | Count |
|---|---|
| 68 | |
| 66 | |
| 29 | |
| 26 | |
| 25 |