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 August 31st. Request your voucher.
I have data that looks like the below:
Date | Product | Account number | Value |
1 april 2024 | Product 1 | 1 | £5 |
1 april 2024 | Product 1 | 2 | £5 |
1 april 2024 | Product 2 | 1 | £5 |
1 april 2024 | Product 3 | 1 | £5 |
Date | Product | Account number | Value | Sales in last 12 months |
1 april 2024 | Product 1 | 1 | £5 | |
1 april 2024 | Product 1 | 2 | £5 | |
1 april 2024 | Product 2 | 1 | £5 | |
1 april 2024 | Product 3 | 1 | £5 |
Solved! Go to Solution.
Hi @gingerclaire ,
When you choose to create a Calculated column, it enables it to be a column in your datasheet rather than in the view.
I also created a table similar to yours, but for the convenience of the DAX code, I chose to convert £5 to 5. If you want the original format, you can use the FORMAT function.
Then I think you can create a calculated column as suparnababu8 mentioned.
Column =
VAR LatestDate = MAX('Table'[Date])
VAR StartDate = EDATE(LatestDate, -12)
RETURN
CALCULATE(
SUM('Table'[Value]),
FILTER(
'Table',
'Table'[Account number] = EARLIER('Table'[Account number]) &&
'Table'[Date] >= StartDate &&
'Table'[Date] <= LatestDate
)
)
Best Regards
Yilong Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
You need to create a calculate columns as mentioned below.'
SalesLast12Months =
VAR CurrentDate = 'Table'[Date]
VAR AccountNumber = 'Table'[Account number]
VAR Last12Months =
CALCULATE(SUM('Table'[Value]),
FILTER(
'Table',
'Table'[Account number] = AccountNumber &&
'Table'[Date] <= CurrentDate &&
'Table'[Date] > EDATE(CurrentDate, -12)
)
)
RETURN Last12Months
The use this calculated columns in your matrix/table chart.
If you need additional info pls follow the below URLs
Hope this helps you!
Thanks!
Hello @gingerclaire ,
Please follow below steps to achieve your requirement.
step1: Please create a calendar table
step2: Create relationship between your calendar table date and sales table date columns
step3: Create a new measure with below DAX:
Total Sales Last 12 Months =
CALCULATE(
SUM(TableName[Value]),
DATESINPERIOD(
'Calendar'[Date],
MAX('Calendar'[Date]),
-12,
MONTH
)
)
Step4: Drag your measure into the table visual to get the required output.
If this post helps, then please consider accepting it as the solution to help other members find it more quickly. Thank You!!
Hi - I want to have this as a column in my data table and not in a visual. Will this work too?
Hi @gingerclaire ,
When you choose to create a Calculated column, it enables it to be a column in your datasheet rather than in the view.
I also created a table similar to yours, but for the convenience of the DAX code, I chose to convert £5 to 5. If you want the original format, you can use the FORMAT function.
Then I think you can create a calculated column as suparnababu8 mentioned.
Column =
VAR LatestDate = MAX('Table'[Date])
VAR StartDate = EDATE(LatestDate, -12)
RETURN
CALCULATE(
SUM('Table'[Value]),
FILTER(
'Table',
'Table'[Account number] = EARLIER('Table'[Account number]) &&
'Table'[Date] >= StartDate &&
'Table'[Date] <= LatestDate
)
)
Best Regards
Yilong Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
User | Count |
---|---|
77 | |
76 | |
36 | |
31 | |
29 |
User | Count |
---|---|
93 | |
79 | |
57 | |
48 | |
48 |