cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Helper I

Creating a Calculated Column when Making a Table

Hi Everyone,

I'm making a Date Table and in it I want to include a calculated Column "Total Order Amount" from 'Orders' Table where "Total Order Amount" column equals Orders[OrderQuantity] * Orders[SalesPrice]:

I used this script to create the Date Table (with the extra calculated column):

But when I do this the "Total Order Amount" Values on the new table are just the whole of all orders combined:

Any way to fix this so the "Total Order Amount" is [OrderQuantity] * [OrderSales] for each particular date instead of the grand total?

Any help would be greatly appreciated.

Thanks----

1 ACCEPTED SOLUTION
Community Support

Based on your description, Please try code as below to create a Calculated Column.

My Sample:

``````Table =
var _table=
CALENDAR(DATE(2013,1,1),DATE(2013,1,31)),
"Weeknum", WEEKNUM([Date]),
"Week Number & Year", "W" & WEEKNUM([Date]) & " " &YEAR([Date]),
"WeekYearNumber", YEAR([Date]) & 100 + WEEKNUM([Date])
)
return
_table,
"Total Order Amount",
SUMX(
FILTER(ALL(Orders),
'Orders'[OrdeDaterKey]=EARLIER([Date])),[OrderQuantity]*[SalesPrice])
)``````

Result is as below.

Best Regards,
Yulia Yan

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

7 REPLIES 7
Community Support

Based on your description, Please try code as below to create a Calculated Column.

My Sample:

``````Table =
var _table=
CALENDAR(DATE(2013,1,1),DATE(2013,1,31)),
"Weeknum", WEEKNUM([Date]),
"Week Number & Year", "W" & WEEKNUM([Date]) & " " &YEAR([Date]),
"WeekYearNumber", YEAR([Date]) & 100 + WEEKNUM([Date])
)
return
_table,
"Total Order Amount",
SUMX(
FILTER(ALL(Orders),
'Orders'[OrdeDaterKey]=EARLIER([Date])),[OrderQuantity]*[SalesPrice])
)``````

Result is as below.

Best Regards,
Yulia Yan

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

Helper I

Thanks!

Super User

@MichaelG1117 Maybe try using RELATEDTABLE in your SUMX although it may not work as the relationship may not technically exist yet as the table is being calculated (created). Could also explore dropping the CALCULATE.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Helper I

I tried taking out the SumX, did not work.

Tried Relatedtable but was unsure what the script would be --- didn't work

Super User

@MichaelG1117 Keep the SUMX. Drop the CALCULATE. Use RELATED or RELATEDTABLE as the first argument for your SUMX

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Super User

HI, @MichaelG1117

I think it is correct because there are no filter part present in table from where total order amount column filter means your column(total order amount) has no data lineage for that table so you have to provide some filter part like product code or product name or orderquantity(as above in your first image) or something from which your column(total order amount) filter according to that

Helper I
I tried:

"Total Order Amount", CALCULATE(Sumx('Orders','Orders'[OrderQuantity]*'Orders'[SalesPrice]),
FILTER(Orders, Orders[OrderDateKey]))

Did not work, though

Announcements

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors