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.
How do I use DAX to create a new table with additional rows? The value in the new rows will be using average of the existing rows for each category (version).
Solved! Go to Solution.
Hi,
Please check the below attached pbix file and the DAX formula for creating a new table.
I believe you have a Calendar Table, like the attached sample pbix file.
NewTable =
UNION( Data,
ADDCOLUMNS (
SUMMARIZE (
ADDCOLUMNS (
ADDCOLUMNS (
ADDCOLUMNS (
SUMMARIZE ( Data, Data[Version], Data[WeekNum] ),
"@rowcount", COUNTROWS ( FILTER ( Data, Data[Version] = EARLIER ( Data[Version] ) ) ),
"@weekoffsetnumber",
MAXX (
FILTER ( 'Calendar', 'Calendar'[WeekNumber] = Data[WeekNum] ),
'Calendar'[WeekOffset]
)
),
"@newweekoffsetnumber", [@weekoffsetnumber] + [@rowcount]
),
"@newweeknumber",
MAXX (
FILTER ( 'Calendar', 'Calendar'[WeekOffset] = [@newweekoffsetnumber] ),
'Calendar'[WeekNumber]
)
),
Data[Version],
[@newweeknumber]
),
"@valueavg",
AVERAGEX (
FILTER ( Data, Data[Version] = EARLIER ( Data[Version] ) ),
Data[Value]
)
)
)
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Hi,
Please check the below attached pbix file and the DAX formula for creating a new table.
I believe you have a Calendar Table, like the attached sample pbix file.
NewTable =
UNION( Data,
ADDCOLUMNS (
SUMMARIZE (
ADDCOLUMNS (
ADDCOLUMNS (
ADDCOLUMNS (
SUMMARIZE ( Data, Data[Version], Data[WeekNum] ),
"@rowcount", COUNTROWS ( FILTER ( Data, Data[Version] = EARLIER ( Data[Version] ) ) ),
"@weekoffsetnumber",
MAXX (
FILTER ( 'Calendar', 'Calendar'[WeekNumber] = Data[WeekNum] ),
'Calendar'[WeekOffset]
)
),
"@newweekoffsetnumber", [@weekoffsetnumber] + [@rowcount]
),
"@newweeknumber",
MAXX (
FILTER ( 'Calendar', 'Calendar'[WeekOffset] = [@newweekoffsetnumber] ),
'Calendar'[WeekNumber]
)
),
Data[Version],
[@newweeknumber]
),
"@valueavg",
AVERAGEX (
FILTER ( Data, Data[Version] = EARLIER ( Data[Version] ) ),
Data[Value]
)
)
)
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Thank you Jihwan, this works very well!
union(Table,
crossjoin(summarize(filter(Table, Table[Week] >=202140 && Table[Week] <=202144), [Week]), AvergaeX(summarize(filter(Table, Table[Week] >=202140 && Table[Week] <=202144), "_1", Average(Table[Value])),[_1])),
crossjoin(summarize(filter(Table, Table[Week] >=202145 && Table[Week] <=202145), [Week]), AvergaeX(summarize(filter(Table, Table[Week] >=202145 && Table[Week] <=202145), "_1", Average(Table[Value])),[_1]))
)
Hi Amit,
Thank you for the fast reply..
Problem is I have about 1000 versions (1st column).. the screenshot is only showing 2 out of 1000 versions..
I also have a calendar table that allows me to lookup the weeknum.
Can you advise? Thank you
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
107 | |
94 | |
77 | |
63 | |
50 |
User | Count |
---|---|
147 | |
106 | |
104 | |
87 | |
61 |