Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Power_It_Up
Helper II
Helper II

Create a new table from the Main Table with criteria

Hi,

 

I currently have this example Main table. I'm only using client A (there are hundreds) and certain countries/items to try and explain this better:-

 

Power_It_Up_0-1744799033251.png

 

I need to create a new table which shows the missing Items based on the data.  So the new table should look like this:-

Power_It_Up_1-1744799100522.png

 

So for England, it has added Item C and a zero because the item exists for Client A, but only for USA.

 

For USA, it has added Item B and Item D with zero's as these exist for England.

 

This methodology has to run through many clients and items and each client will have different countries and items associated to them.

 

Thank you in advance for any pointers. 🙂

 

 

 

2 ACCEPTED SOLUTIONS
pankajnamekar25
Super User
Super User

 

You can use below DAX code to calculated table

 

ResultTable =

VAR ClientsCountries =

    SUMMARIZE(MainTable, MainTable[Client], MainTable[Country])

VAR Items =

    VALUES(MainTable[Item])

RETURN

    GENERATE(

        ClientsCountries,

        ADDCOLUMNS(

            Items,

            "AmountSold",

            CALCULATE(

                SUM(MainTable[AmountSold]),

                FILTER(

                    MainTable,

                    MainTable[Client] = EARLIER(MainTable[Client])

                        && MainTable[Country] = EARLIER(MainTable[Country])

                        && MainTable[Item] = EARLIER(MainTable[Item])

                )

            )

        )

    )

 

 

 

Thanks,
 Pankaj Namekar | LinkedIn

If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.

View solution in original post

Thanks @pankajnamekar25 for the quick reply.  By switching [AmountSold] to "Don't Summarize" does the trrick.  How can I convert the blanks to a zero or even text?  Thank you again. 🙂

Power_It_Up_0-1744800532769.png

 

Edit: Please ignore. I changed this line of code: 

Power_It_Up_0-1744801102279.png

 

Thanks again. 🙂 P.S. I may be back lol!

 

 

View solution in original post

4 REPLIES 4
pankajnamekar25
Super User
Super User

 

You can use below DAX code to calculated table

 

ResultTable =

VAR ClientsCountries =

    SUMMARIZE(MainTable, MainTable[Client], MainTable[Country])

VAR Items =

    VALUES(MainTable[Item])

RETURN

    GENERATE(

        ClientsCountries,

        ADDCOLUMNS(

            Items,

            "AmountSold",

            CALCULATE(

                SUM(MainTable[AmountSold]),

                FILTER(

                    MainTable,

                    MainTable[Client] = EARLIER(MainTable[Client])

                        && MainTable[Country] = EARLIER(MainTable[Country])

                        && MainTable[Item] = EARLIER(MainTable[Item])

                )

            )

        )

    )

 

 

 

Thanks,
 Pankaj Namekar | LinkedIn

If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.

Hi @pankajnamekar25 . 

 

I'm hoping you can direct me a little further with this as I need to add something.

 

This is the current code which you created for me and works brilliantly:-

ResultTable =

VAR ClientsCountries =

    SUMMARIZE(MainTable, MainTable[Client], MainTable[Country])

VAR Items =

    VALUES(MainTable[Item])

RETURN

    GENERATE(

        ClientsCountries,

        ADDCOLUMNS(

            Items,

            "AmountSold",

            CALCULATE(

                SUM(MainTable[AmountSold]),

                FILTER(

                    MainTable,

                    MainTable[Client] = EARLIER(MainTable[Client])

                        && MainTable[Country] = EARLIER(MainTable[Country])

                        && MainTable[Item] = EARLIER(MainTable[Item])

                )

            )

        )

    )

 

In the very first line SUMMARIZE(......), am I able to add fields from other tables which I have already created relationships for? 

 

Many thanks. 🙂

Thanks @pankajnamekar25 for the quick reply.  By switching [AmountSold] to "Don't Summarize" does the trrick.  How can I convert the blanks to a zero or even text?  Thank you again. 🙂

Power_It_Up_0-1744800532769.png

 

Edit: Please ignore. I changed this line of code: 

Power_It_Up_0-1744801102279.png

 

Thanks again. 🙂 P.S. I may be back lol!

 

 

miTutorials
Super User
Super User

I Suggest doing this transformation in your source than doing this in PowerBI !!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.