Forum Discussion
SQL to DAX: Get SalesPerson Region on a specific date into a measure
- 7 years ago
Hi P_R
Create relationships as below, reference here
Create measures in SalesPersonSalesTeam table
Start = MAX([StartDate]) end = IF(MAX([ExpirationDate])=BLANK(),DATE(2999,12,31),MAX([ExpirationDate])) Measure = CALCULATE(SUM('Order'[amount]),FILTER('Order',[datestamp]>=[Start]&&[datestamp]<=[end]))Best Regards
Maggie
Hi P_R
Create relationships as below, reference here
Create measures in SalesPersonSalesTeam table
Start = MAX([StartDate])
end = IF(MAX([ExpirationDate])=BLANK(),DATE(2999,12,31),MAX([ExpirationDate]))
Measure = CALCULATE(SUM('Order'[amount]),FILTER('Order',[datestamp]>=[Start]&&[datestamp]<=[end]))
Best Regards
Maggie
Thank you for your reply. I think this will work for the question i asked. I have few more bits after getting the measure which is throwing me error. My question remains the same.
Your solution provides me a mesaure that is calculating amount on the salespersonsalesteam table but is there a way i can create a measure which shows corresponding Sales Group in Order table for each row?
- v-juanli-msft7 years ago
Community Support
Hi P_R
Sorry for inconvenience.
I find a workaround.
Create the relationships like this
Create measures
Start = VAR condition1 = CALCULATE ( MAX ( SalesPersonSalesTeam[ExpirationDate] ), ALLEXCEPT ( SalesPersonSalesTeam, SalesPersonSalesTeam[SalesPersonid] ) ) RETURN IF ( ISBLANK ( MAX ( [ExpirationDate] ) ), IF ( MAX ( SalesPersonSalesTeam[StartDate] ) < condition1, condition1, MAX ( SalesPersonSalesTeam[StartDate] ) ), MAX ( [StartDate] ) ) end = IF(MAX([ExpirationDate])=BLANK(),DATE(2099,1,1),MAX([ExpirationDate])) flag1 = IF(MAX('Order'[datestamp])<=[end]&&MAX('Order'[datestamp])>=[Start],1,0) flag2 = IF(MAX(SalesPersonSalesTeam[SalesPersonid])=MAX('Order'[salespersonid]),1,0)Add 'SalesPersonSalesTeam' [SalesGroup] in the 'Order' table, add [flag1] and [flag2] in the Visual level filter.
Please refer to my pbix->page2
Best Regards
Maggie