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
Anonymous
Not applicable

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
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

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.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

5 REPLIES 5
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

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.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

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.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
amitchandak
Super User
Super User

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

 

 

Anonymous
Not applicable

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.



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))))

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.