cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sach18 Helper III
Helper III

Set Columns in two tables as a row in a new table

I have a requirement where I have to calculate the NetSales with the lookup table shown in below image. 

table1.1.JPGrate.JPG

can i create new table as shown below ?
newTable.JPG

 


Thanks in advance. Please let me know if this is possible in desktop. I have tried the same in Power query and i get the rows Quantity1, Quantity2 and Quantity3 as they are direct data. Please help me on the above requirement.
 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft v-jayw-msft
Microsoft

Re: Set Columns in two tables as a row in a new table

Hi @sach18 ,

 

You can create a calculated table, please refer to the formula below.

New Table =
DISTINCT (
    UNION (
        SELECTCOLUMNS (
            'Table',
            "quantity", "quantity",
            "2018", CALCULATE (
                SUM ( 'Table'[quantity] ),
                FILTER ( 'Table', 'Table'[date] = 2018 )
            ),
            "2019", CALCULATE (
                SUM ( 'Table'[quantity] ),
                FILTER ( 'Table', 'Table'[date] = 2019 )
            )
        ),
        SELECTCOLUMNS (
            'Table',
            "quantity", "sales",
            "2018", CALCULATE ( SUM ( 'Table'[sales] ), FILTER ( 'Table', 'Table'[date] = 2018 ) ),
            "2019", CALCULATE ( SUM ( 'Table'[sales] ), FILTER ( 'Table', 'Table'[date] = 2019 ) )
        )
    )
)

1.PNG2.PNG

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Super User IV
Super User IV

Re: Set Columns in two tables as a row in a new table

What is the formula for nestsales1 and netsales2?

TO get that kind of display, you have a property in matrix visualization. Show on row. That will you columns on row. And then drag year on the column. 

 

In case you have date prefer using a calendar for date, month and year etc

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.

Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

 

 





Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
In case it does not help, please provide additional information and mark me with @
My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP,
HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Super User! Linkedin


sach18 Helper III
Helper III

Re: Set Columns in two tables as a row in a new table

Thanks for that @amitchandak . The formula for netsales1 is Rate1 * Quantity1 and for netSales2 is Rate2 * Quantity2

My actual requirement is to get as the below image.
ytd.JPG

 
I actually need YTD columns for Quantity and sales respectively. If I create a table as i said in the previous message then I thought I will get YTD columns by using measures. 
Let me know if we can do anything to get as shown in above fig.



Super User IV
Super User IV

Re: Set Columns in two tables as a row in a new table

You can get YTD like this. But kind of display you need is a big challenge

nets Sales ytd= CALCULATE(SUMX(Table,Rate1 * Quantity1),DATESYTD('Date'[Date]))
nets Sales2ytd= = CALCULATE(SUMX(Table,Rate1 * Quantity1),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year))))




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
In case it does not help, please provide additional information and mark me with @
My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP,
HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Super User! Linkedin


Highlighted
Microsoft v-jayw-msft
Microsoft

Re: Set Columns in two tables as a row in a new table

Hi @sach18 ,

 

You can create a calculated table, please refer to the formula below.

New Table =
DISTINCT (
    UNION (
        SELECTCOLUMNS (
            'Table',
            "quantity", "quantity",
            "2018", CALCULATE (
                SUM ( 'Table'[quantity] ),
                FILTER ( 'Table', 'Table'[date] = 2018 )
            ),
            "2019", CALCULATE (
                SUM ( 'Table'[quantity] ),
                FILTER ( 'Table', 'Table'[date] = 2019 )
            )
        ),
        SELECTCOLUMNS (
            'Table',
            "quantity", "sales",
            "2018", CALCULATE ( SUM ( 'Table'[sales] ), FILTER ( 'Table', 'Table'[date] = 2018 ) ),
            "2019", CALCULATE ( SUM ( 'Table'[sales] ), FILTER ( 'Table', 'Table'[date] = 2019 ) )
        )
    )
)

1.PNG2.PNG

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Microsoft v-jayw-msft
Microsoft

Re: Set Columns in two tables as a row in a new table

Hi @sach18 ,

 

Have your problem be solved? Please consider accept the answer as a solution if it worked.

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors