We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi Experts
What is the SQL equivalent of the following DAX (Power BI) Formula
AOV = CALCULATE(SUM(FACTSalesOrderTable[Gross_Order_Value]),ALLEXCEPT(FACTSalesOrderTable,FACTSalesOrderTable[increment_id]))
Solved! Go to Solution.
AOV =
CALCULATE(
SUM( FACTSalesOrderTable[Gross_Order_Value] ),
ALLEXCEPT(
FACTSalesOrderTable,
FACTSalesOrderTable[increment_id]
)
)
// is equivalent to this SQL query:
SELECT
sum( so[Gross_Order_Value] )
from dbo.FACTSalesOrderTables as so
where (
so.increment_id in (
// 1. if there is an active filter on increment_id
// then you need all the values that the filter
// uses. All other filters are removed from the
// expanded fact table.
// 2. if there's no active filter on increment_id
// this where clause must disappear from the
// query completely.
// This is the semantics of ALLEXCEPT.
)
)
AOV =
CALCULATE(
SUM( FACTSalesOrderTable[Gross_Order_Value] ),
ALLEXCEPT(
FACTSalesOrderTable,
FACTSalesOrderTable[increment_id]
)
)
// is equivalent to this SQL query:
SELECT
sum( so[Gross_Order_Value] )
from dbo.FACTSalesOrderTables as so
where (
so.increment_id in (
// 1. if there is an active filter on increment_id
// then you need all the values that the filter
// uses. All other filters are removed from the
// expanded fact table.
// 2. if there's no active filter on increment_id
// this where clause must disappear from the
// query completely.
// This is the semantics of ALLEXCEPT.
)
)
Hello @Anonymous
You should use a window function.
Try something like the following:
SELECT dimension1
, dimension2,
SUM(Gross_Order_Value) OVER (PARTITION BY increment_id) AS AOV
FROM FACTSalesOrderTable
thanks thenistoklis and daxer
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 53 | |
| 38 | |
| 33 | |
| 16 | |
| 16 |
| User | Count |
|---|---|
| 66 | |
| 63 | |
| 37 | |
| 34 | |
| 22 |