The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
I have the below table layout and I created the datamodel based on the columns highlighted in the yellow. Basically in the contract table in the center contractid is primary key But both invoice and contractsnapshot table both can have many records for same contractid.
The result I would like to get is the last green table. Everything ok except the disticntcontractcount field. I am not able to get to the invoice.invyr in the formula its throwing error. Please help me how to solve this ?
DistinctContractcount= CALCULATE(DISTINCTCOUNT(ContractSnapshot[ContractID]),ContractSnapshot[SnapshotYear]=Related(Invoice[InvYr]))
Solved! Go to Solution.
Hi @AnonJ,
Please try this:
VAR _Year = MAX(Invoice[InvYr]
VAR _Result =
CALCULATE(
DISTINCTCOUNT(ContractSnapshot[ContractID])
FILTER(
ALL(ContractSnapshot),
ContractSnapshot[SnapshotYear] = _Year
)
)
RETURN
_Result
Proud to be a Super User!
Hi @AnonJ,
Please try this:
VAR _Year = MAX(Invoice[InvYr]
VAR _Result =
CALCULATE(
DISTINCTCOUNT(ContractSnapshot[ContractID])
FILTER(
ALL(ContractSnapshot),
ContractSnapshot[SnapshotYear] = _Year
)
)
RETURN
_Result
Proud to be a Super User!
Thank you , sorry its not working, its gives me 3 contracts for both 2021 and 2022 years where it should be 3 for 2021 and 2 for 2022. Secondly, I am unable to establish a relationship between invoice and contractsnapshot. The relationship to these tables I set up using the middle table contract
Try:
DistinctContractCount =
CALCULATE(
DISTINCTCOUNT(ContractSnapshot[ContractID]),
ContractSnapshot[SnapshotYear] = MAX(Invoice[InvYr]) // Reference the current invoice year context
)
Verify that relationships among the tables are set appropriately, especially between Invoice and ContractSnapshot.
💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn
User | Count |
---|---|
68 | |
63 | |
59 | |
54 | |
28 |
User | Count |
---|---|
182 | |
81 | |
64 | |
46 | |
41 |