Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

New table using values from two other tables

Hello,

 

I am working on analysing businesses' financial statements and need some help with writing DAX code to make a new table using values from another table, and names from another table. I already posted a similar question (New column in new table based on values of other tables ) but my problem has gotten a bit more complex so the solution there doesn't apply to this. Maybe Mahesh0016 has an answer for this as well? 😄

 

Say I have two tables, Table 1 and Table 2.

 

Table 1 (which has info on shop names, year, the original line item name from each shop's financial statements and the value corresponding to that line item)

Shop nameYearLine item nameValue
Shop A2022current assets total10
Shop A2022non-current assets total20
Shop A2022current liabilities30
Shop B2022CA total40
Shop B2022NCA total50
Shop B2022CL total60
Shop B2021CA total70
Shop B2021NCA total80
Shop B2021CL total90

 

Table 2 (which has the original line item name and a new name for consistency)

Line item nameNew name
current assets totalTotal current assets
CA totalTotal current assets
non-current assets totalTotal non-current assets
NCA totalTotal non-current assets
current liabilities totalTotal current liabilities
CL totalTotal current liabilities

 

I want to use information from Tables 1 and 2 to ultimately get a table like this (let's call it Table 3):

 

Table 3

 

Shop nameYearTotal current assetsTotal non-current liabilitiesTotal current liabilities
Shop A2022102030
Shop B2022405060
Shop B2021708090

 

Many thanks in advance!

  • FreemanZ's avatar
    FreemanZ
    3 years ago

    hi Anonymous 

    something like this?

    Table3 = 
    ADDCOLUMNS(
        SUMMARIZE(
            Table1,
            Table1[Shop Name],
            Table1[Year]
        ),
        "Total current assets",
        CALCULATE(
            SUM(Table1[Value]),
            Table2[New Name]="Total current assets"
        ),
        "Total non-current assets",
        CALCULATE(
            SUM(Table1[Value]),
            Table2[New Name]="Total non-current assets"
        ),
        "Total current liabilities",
        CALCULATE(
            SUM(Table1[Value]),
            Table2[New Name]="Total current liabilities"
        )
    )

     

4 Replies

  • hi Anonymous 

    try to plot a matrix visual directly, like:

    or?

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks, that's a good idea! But I would prefer to do it without having to plot a visual....is there a way to just use DAX to make the table?

       

      Reason is I need this table to add to my data model. If I were to plot a matrix visual I'd have to save it as a csv and then load that into my model which I'd rather avoid doing.

      • FreemanZ's avatar
        FreemanZ
        Super User

        hi Anonymous 

        something like this?

        Table3 = 
        ADDCOLUMNS(
            SUMMARIZE(
                Table1,
                Table1[Shop Name],
                Table1[Year]
            ),
            "Total current assets",
            CALCULATE(
                SUM(Table1[Value]),
                Table2[New Name]="Total current assets"
            ),
            "Total non-current assets",
            CALCULATE(
                SUM(Table1[Value]),
                Table2[New Name]="Total non-current assets"
            ),
            "Total current liabilities",
            CALCULATE(
                SUM(Table1[Value]),
                Table2[New Name]="Total current liabilities"
            )
        )