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
gurujeet
Frequent Visitor

Creating table in DAX with appended rows

I have a table that looks like this:

Year, Amount A, Amount B, Amount C

 

I'd like to create a new table like:

Year, Amount

 

where for existing Year's, Amount=Amount A (i.e. starting table less Amount B and Amount C and Amount A renamed Amount), 

and add rows with Year = MAX(Year)+1 and Amount= Amount B where Year=MAX(Year),

and add rows with Year = MAX(Year)+2 and Amount= Amount C where Year=MAX(Year)

 

Any suggestions, thanks?

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @gurujeet 

 

Assume your original table is called 'Table', you can create a new table with below DAX code.

Table 2 = 
var maxYear = MAX('Table'[Year])
var table1 = SELECTCOLUMNS('Table',"Year",'Table'[Year],"Amount",'Table'[Amount A])
var table2 = {(maxYear+1,MAXX(FILTER('Table','Table'[Year]=maxYear),'Table'[Amount B]))}
var table3 = {(maxYear+2,MAXX(FILTER('Table','Table'[Year]=maxYear),'Table'[Amount C]))}
return
UNION(table1,table2,table3)

21102505.jpg

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @gurujeet 

 

Assume your original table is called 'Table', you can create a new table with below DAX code.

Table 2 = 
var maxYear = MAX('Table'[Year])
var table1 = SELECTCOLUMNS('Table',"Year",'Table'[Year],"Amount",'Table'[Amount A])
var table2 = {(maxYear+1,MAXX(FILTER('Table','Table'[Year]=maxYear),'Table'[Amount B]))}
var table3 = {(maxYear+2,MAXX(FILTER('Table','Table'[Year]=maxYear),'Table'[Amount C]))}
return
UNION(table1,table2,table3)

21102505.jpg

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

gurujeet
Frequent Visitor

Here is a sample input table:

 

Year    Amount A    Amount B    Amount C
2019     100               200              300
2020     110               210              310
2021     120               220              320

 

...and the desired output table:

Year    Amount
2019     100
2020     110
2021     120
2022     220
2023     320

mahoneypat
Employee
Employee

Please share a simple mock table of data (in a copy/paste format, not an image) along with desired output.  This will help you get a specific solution.

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.