The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hello,
I have a measure that calculates 'paid' amounts over a dynamic period (Rolling 12 mos or Year-to-date).
The end of date period is defined by another measure (master_current_date) which gets the Max date value of paid dates available:
Master_CURRENT_DATE =
VAR MXDT = --Get latest "paid date" from medical_claim_line_items.
CALCULATE(
MAX(
'Claims'[paid_date]),
ALL('Claims')
)
RETURN -- Return end of month for last full month of claims.
IF(
EOMONTH(MXDT,0) > MXDT, EOMONTH(MXDT,-1),
EOMONTH(MXDT,0)
)
This is then used to calculate either a start date of 12 months ago for Rolling 12 or beginning of year for YTD and returning 'paid' amount for bills occuring in that period.
Most measures have no problems with this 'Master_Current_date' measure at all. However! One or 2 measures throw an error when combined with some 'Claims' category hierarchies like the below:
THE PUZZLING PART: When I hard code the end date instead of using 'master_current_date' like DATE(2024,11,31) it works. But even doing
Solved! Go to Solution.
Hi,
Thanks for the solution SacheeTh offered, and i want to offer some more information for user to refer to,
hello @jacmac , please check that whether your [master-current-date] will return blank sometimes, if it return blank, then it will return the error, you can refer to the following similar thread.
Solved: An argument or function DATE has wrong data type w... - Microsoft Fabric Community
Solved: An Argument of Function Date has wrong data type o... - Microsoft Fabric Community
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
Thanks for the solution SacheeTh offered, and i want to offer some more information for user to refer to,
hello @jacmac , please check that whether your [master-current-date] will return blank sometimes, if it return blank, then it will return the error, you can refer to the following similar thread.
Solved: An argument or function DATE has wrong data type w... - Microsoft Fabric Community
Solved: An Argument of Function Date has wrong data type o... - Microsoft Fabric Community
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
HI @Anonymous ,
You were correct! When measures referencing the 'master_current_date' were used in matrix tables, the measure could return a blank or different value. Changing the "ALL" filter to 'REMOVEFILTERS()' to remove any filter context from the time measure fixed the issue.
Thanks!
Hi @jacmac, The issue you're experiencing likely stems from how Power BI handles implicit data type conversions and how measures interact with certain contexts, such as hierarchies. Specifically, the problem arises when the Master_CURRENT_DATE measure is used in calculations and evaluated dynamically. Here's how to address this issue:
Ensure Master_CURRENT_DATE Returns a Single Value
Measures like Master_CURRENT_DATE must always return a scalar value (a single date) and not an array or a table. To ensure this, use SELECTEDVALUE or wrap it with MAX to handle any ambiguity in context.
Master_CURRENT_DATE = VAR MXDT = CALCULATE( MAX('Claims'[paid_date]), ALL('Claims') ) RETURN IF( EOMONTH(MXDT, 0) > MXDT, EOMONTH(MXDT, -1), EOMONTH(MXDT, 0) )
Use a Consistent Data Type for Date Calculations
While your Master_CURRENT_DATE is returning a valid date, Power BI may encounter issues when this measure interacts with other measures or columns. Explicitly wrap the measure in a DATE function if needed to enforce the correct type:
DATE(YEAR([Master_CURRENT_DATE]), MONTH([Master_CURRENT_DATE]), DAY([Master_CURRENT_DATE]))
However, this is redundant if Master_CURRENT_DATE already returns a valid DATE value.
Handle Context Issues in Related Measures
The error might arise from how the date measure interacts with other contexts (e.g., Claims categories). When used in your rolling calculations, ensure the context is explicitly controlled using FILTER or ALL. Here's an example:
Rolling_12_Paid = VAR StartDate = EOMONTH([Master_CURRENT_DATE], -12) + 1 VAR EndDate = [Master_CURRENT_DATE] RETURN CALCULATE( SUM('Claims'[paid_amount]), 'Claims'[paid_date] >= StartDate && 'Claims'[paid_date] <= EndDate )
The key is ensuring Master_CURRENT_DATE is calculated consistently within the desired filter context.
Debug Context Using Temporary Columns
Create calculated columns or measures to debug the intermediate outputs:
Avoid Using Measures in DATE Function Unless Necessary
Instead of constructing a date using DATE(YEAR(...), MONTH(...), DAY(...)), use the date measure directly if it already returns a valid date. The DATE function may not be necessary unless you are manually constructing dates from individual components.
Check Master_CURRENT_DATE Output:
Master_Current_Date_Debug = [Master_CURRENT_DATE]
Check Start and End Dates for Rolling Calculations:
Start_Date_Debug = EOMONTH([Master_CURRENT_DATE], -12) + 1 End_Date_Debug = [Master_CURRENT_DATE]
Test with Static Values: Replace [Master_CURRENT_DATE] with a static date and verify if it works. This helps identify if the issue is tied to dynamic context evaluation.
By carefully controlling the context and ensuring consistent data types, you should be able to resolve the errors caused by dynamic date calculations.