Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
I have the following PowerBI DAX Measure. It has to be this complex for a number of reasons due to the structure of the data. The measure works fine, and it returns me the number of active contracts for each customer. This displays nicely on a visual grid and gives a total of all the active contracts for all the customers.
ActiveContracts = CALCULATE(COUNTROWS(RELATEDTABLE(Contracts)),
FILTER(Contracts,
(
Contracts[StartDate] >= CALCULATE(MIN(DateRange[Date]), ALLEXCEPT(DateRange, DateRange[Date])) &&
Contracts[StartDate] <= CALCULATE(MAX(DateRange[Date]), ALLEXCEPT(DateRange, DateRange[Date]))
)
||
(
Contracts[End Date] >= CALCULATE(MIN(DateRange[Date]), ALLEXCEPT(DateRange, DateRange[Date])) &&
Contracts[End Date] <= CALCULATE(MAX(DateRange[Date]), ALLEXCEPT(DateRange, DateRange[Date]))
)
||
(
Contracts[StartDate] <= CALCULATE(MIN(DateRange[Date]), ALLEXCEPT(DateRange, DateRange[Date])) &&
Contracts[End Date] >= CALCULATE(MAX(DateRange[Date]), ALLEXCEPT(DateRange, DateRange[Date]))
)
)
)However, I only need the first result, or even more simply, just the fact that there is a result (i.e. an active contract for a customer).
I have tried a number of things and the closest I can get is another measure on top of the one above:
HasContract = CALCULATE(IF(ISBLANK([CCActiveContract]), 0, 1))
This then works on the row level, but when I total the column with this new measure, it gives a total of 1, whereas I want a count of all customers with an active contract?
What am I missing?
Thanks
Solved! Go to Solution.
Thanks SuperTom,
I am on my way using similar:
ContractPerCustomer = SUMX(Customer, IF([ActiveContracts] > 0, 1, 0))
Cheers
Hey,
without sample data it's a litte difficult, but I would give this a try by creating a new measure
SUMX(
VALUES('tableWithCustomer'[Customer],
IF([AcitveContracts] > 0
,1
,BLANK()
)
)Hopefully this gets you started
Regards
Tom
Thanks SuperTom,
I am on my way using similar:
ContractPerCustomer = SUMX(Customer, IF([ActiveContracts] > 0, 1, 0))
Cheers
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 40 | |
| 38 | |
| 36 | |
| 29 | |
| 28 |
| User | Count |
|---|---|
| 127 | |
| 88 | |
| 78 | |
| 66 | |
| 64 |