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!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
Hi all
how to calculate pervious 6 month when date column is text format?
here is the sample data link:
I have these 2 calculations:
But when I don't choose the date hierarchy, the table has only 2 layer, but the calculated numbers are wrong.
please help
Solved! Go to Solution.
Hi @MikeCheng ,
Thank you for the update. Please refer below.
1. When you drag a Date column (real Date type) into visuals or DAX, Power BI automatically creates a hidden “auto date table” this is where [Date], [Year], [MonthNo], [MonthName], etc.
DATESINPERIOD('Raw data'[年月].[Date], MAX('Raw data'[年月].[Date]), -6, MONTH)
[年月].[Date] refers to hidden auto table, not your column directly. But when your '年月' is text, Power BI does not create this auto table DAX functions like DATESINPERIOD() need a real date column, so they return blank. That’s why originally your measure returned nothing you gave DAX a text column, not a real date column.
2. When you try the below measure
previous 6 month sum by text =
CALCULATE (
SUM('Raw data'[acture amount]),
DATESINPERIOD('Raw data'[年月], MAX('Raw data'[年月]), -6, MONTH)
)
Power BI did not use 'Raw data'[年月] (the text column) directly instead, it internally coerced it into a date type temporarily because the function DATESINPERIOD() can only operate on real dates. If all values are in a recognizable YYYY-MM or YYYY/MM format, Power BI can parse them into real dates, and your DAX starts work even though '年月'’s declared type is Text. It is an implicit type conversion: Text “2023-06” --> Date(2023, 6, 1).
I hope this information helps. Please do let us know if you have any further queries.
Regards,
Dinesh
Sales Last 6 Months =
CALCULATE(
SUM(YourTable[YourSalesColumn]), // Replace with your actual measure/column
DATEADD('Date'[Date], -6, MONTH)
)
Sales Previous 6 Months =
VAR MaxDate = MAX(DateTable[Date]) // Use your Date table's date column
VAR SixMonthsAgo = DATESINPERIOD(DateTable[Date], MaxDate, -6, MONTH)
RETURN
CALCULATE(
SUM(YourTable[YourSalesColumn]), // Replace with your actual measure/column
SixMonthsAgo
)
you need to create a date table and try this to create a measure
Proud to be a Super User!
Hi Ryan
can you explain why does it have to create a date table?
I found out that if I change my Dax to below (just delete .[Date] in my original Dax) and the answer calculated correctly
*in this case, I don't choose the date hierarchy as well.
Hi @MikeCheng ,
Thank you for the update. Please refer below.
1. When you drag a Date column (real Date type) into visuals or DAX, Power BI automatically creates a hidden “auto date table” this is where [Date], [Year], [MonthNo], [MonthName], etc.
DATESINPERIOD('Raw data'[年月].[Date], MAX('Raw data'[年月].[Date]), -6, MONTH)
[年月].[Date] refers to hidden auto table, not your column directly. But when your '年月' is text, Power BI does not create this auto table DAX functions like DATESINPERIOD() need a real date column, so they return blank. That’s why originally your measure returned nothing you gave DAX a text column, not a real date column.
2. When you try the below measure
previous 6 month sum by text =
CALCULATE (
SUM('Raw data'[acture amount]),
DATESINPERIOD('Raw data'[年月], MAX('Raw data'[年月]), -6, MONTH)
)
Power BI did not use 'Raw data'[年月] (the text column) directly instead, it internally coerced it into a date type temporarily because the function DATESINPERIOD() can only operate on real dates. If all values are in a recognizable YYYY-MM or YYYY/MM format, Power BI can parse them into real dates, and your DAX starts work even though '年月'’s declared type is Text. It is an implicit type conversion: Text “2023-06” --> Date(2023, 6, 1).
I hope this information helps. Please do let us know if you have any further queries.
Regards,
Dinesh
Hi @MikeCheng ,
We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. And, if you have any further query do let us know.
Regards,
Dinesh
Hi @MikeCheng ,
Could you please try the proposed solution shared by @ryan_mayu ? Let us know if you’re still facing the same issue we’ll be happy to assist you further.
Regards,
Dinesh
Hi @MikeCheng ,
Thank you for reaching out to the Microsoft Community Forum.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot). Do not include sensitive information. Do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided.
Regards,
Dinesh
Hi @MikeCheng ,
We haven’t heard from you on the last response and was just checking back to see, Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot). Do not include sensitive information. Do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided.
Regards,
Dinesh
Hi @MikeCheng ,
We haven’t heard from you on the last response and was just checking back to see, Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot). Do not include sensitive information. Do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided.
Regards,
Dinesh
Hi @MikeCheng ,
We haven’t heard from you on the last response and was just checking back to see, Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot). Do not include sensitive information. Do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided.
Regards,
Dinesh
Just convert the date into Date Type and only keep the date in matrix you can remove Year and Month etc from the matrix
Did I answer your question? If so, please mark my post as a solution!
Proud to be a Super User!