Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
newhopepdx
Helper III
Helper III

Create Table from adjusted date range based on slicer

Have a matrix with: Customer, the # of transactions previous period, # transaction in the slicer-based period.

And a slicer that sets the start and ending dates.

Am using the measure below to calculate the previous period data.

Wanting to also (when clicking on a specific Customer in the matrix) fill a table visual with the transactions that made up the rows counted by the measure for that customer.

 

Seems like I could duplicate the Transaction table and set a filter on it, then use it as the basis for the table visual. But how do you create such a table dynamically?

 

Transactions SPLY = 

VAR __maxDate = MAX('Date'[Date])
VAR __minDate = MIN('Date'[Date])
VAR __startDt = DATE( YEAR( __minDate)-1, MONTH(__minDate), DAY(__minDate))
VAR __endDt = DATE( YEAR(__maxDate)-1, MONTH(__maxDate), DAY( __maxDate))
VAR __return = CALCULATE(
       COUNTROWS('FinancialTrans'),
       'Date'[Date] >= __startDt && 'Date'[Date] <= __endDt
)
RETURN
__return
1 ACCEPTED SOLUTION
AmiraBedh
Super User
Super User


You don't need to duplicate the Transactions table manually instead you can use a DAX calculated table or a measure that feeds into your table visual.

SPLY Transactions Table =
VAR __minDate = MIN('Date'[Date])
VAR __maxDate = MAX('Date'[Date])
VAR __startDate = DATE(YEAR(__minDate) - 1, MONTH(__minDate), DAY(__minDate))
VAR __endDate = DATE(YEAR(__maxDate) - 1, MONTH(__maxDate), DAY(__maxDate))

RETURN
FILTER (
ADDCOLUMNS (
'FinancialTrans',
"TransactionDate", RELATED('Date'[Date])
),
[TransactionDate] >= __startDate &&
[TransactionDate] <= __endDate
)

If Customer is in your FinancialTrans table or related to it, then clicking a customer in the matrix will contextually filter this table too.

Or you can use a measure :

Show SPLY Txn =
VAR __minDate = MIN('Date'[Date])
VAR __maxDate = MAX('Date'[Date])
VAR __startDate = DATE(YEAR(__minDate) - 1, MONTH(__minDate), DAY(__minDate))
VAR __endDate = DATE(YEAR(__maxDate) - 1, MONTH(__maxDate), DAY(__maxDate))

RETURN
IF (
'FinancialTrans'[Date] >= __startDate &&
'FinancialTrans'[Date] <= __endDate,
1,
0
)

Then use a visual-level filter on the table to show only rows where Show SPLY Txn = 1.


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

View solution in original post

5 REPLIES 5
danextian
Super User
Super User

Hi @newhopepdx 

 

A basic SAMEPERIODLASTYEAR time intelligence calculation on a dates table would work if the goal were only to compute the previous year's value. In that case, a related dates table would be sufficient. However, this method only displays rows within the selected date range, even though the calculation itself still retrieves the previous year's data. To overcome this limitation and display transactions contributing to the previous year's total, a disconnected table is required - which is a table that is not directly related to the model’s fact tables through relationships. Instead, it is used as an independent reference, often for calculations, parameter selections, or alternative filtering logic.

 

You can see in the image below that although the selected dates are from 2024, transaction dates from the prior year are still visible.

danextian_0-1742729456401.png

The measures used are:

Sum of Amount (Disconnected) = 
CALCULATE (
    [Sum of Amount],
    KEEPFILTERS (
        TREATAS ( VALUES ( DisconnectedCalendar[Date] ), CalendarTable[Date] )
    )
)

Previous Year Sum of Amount (Disconnected) =
CALCULATE (
    [Sum of Amount],
    KEEPFILTERS (
        TREATAS (
            SELECTCOLUMNS (
                DisconnectedCalendar,
                "Date", DATEADD ( DisconnectedCalendar[Date], -1, YEAR )
            ),
            CalendarTable[Date]
        )
    )
)

 

Please see the attached sample pbix.

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
rohit1991
Super User
Super User

Hi @newhopepdx ,

To dynamically display transaction details from the previous period based on a slicer-defined date range and a selected customer in your matrix, you can create a calculated table that adjusts to both the slicer and user interactions. The idea is to replicate the time-shifted logic you’ve used in your measure, but apply it to a table that filters the actual rows of transaction data.

 

By referencing the start and end dates from the slicer and shifting them back by one year, and filtering based on the selected customer from the matrix, the calculated table will only return relevant transaction records for that customer in the corresponding previous period. This approach allows you to use the table visual effectively without needing to duplicate your entire transaction table manually.

 

TransactionsSPLYDetails =
VAR __minDate = MIN('Date'[Date])
VAR __maxDate = MAX('Date'[Date])
VAR __startDt = DATE(YEAR(__minDate) - 1, MONTH(__minDate), DAY(__minDate))
VAR __endDt = DATE(YEAR(__maxDate) - 1, MONTH(__maxDate), DAY(__maxDate))
VAR __selectedCustomer = SELECTEDVALUE('Customer'[CustomerName]) -- Adjust field name if needed

RETURN
CALCULATETABLE(
    'FinancialTrans',
    'FinancialTrans'[CustomerName] = __selectedCustomer,
    'Date'[Date] >= __startDt,
    'Date'[Date] <= __endDt
)

 

Passionate about leveraging data analytics to drive strategic decision-making and foster business growth.

Connect with me on LinkedIn: Rohit Kumar

AmiraBedh
Super User
Super User


You don't need to duplicate the Transactions table manually instead you can use a DAX calculated table or a measure that feeds into your table visual.

SPLY Transactions Table =
VAR __minDate = MIN('Date'[Date])
VAR __maxDate = MAX('Date'[Date])
VAR __startDate = DATE(YEAR(__minDate) - 1, MONTH(__minDate), DAY(__minDate))
VAR __endDate = DATE(YEAR(__maxDate) - 1, MONTH(__maxDate), DAY(__maxDate))

RETURN
FILTER (
ADDCOLUMNS (
'FinancialTrans',
"TransactionDate", RELATED('Date'[Date])
),
[TransactionDate] >= __startDate &&
[TransactionDate] <= __endDate
)

If Customer is in your FinancialTrans table or related to it, then clicking a customer in the matrix will contextually filter this table too.

Or you can use a measure :

Show SPLY Txn =
VAR __minDate = MIN('Date'[Date])
VAR __maxDate = MAX('Date'[Date])
VAR __startDate = DATE(YEAR(__minDate) - 1, MONTH(__minDate), DAY(__minDate))
VAR __endDate = DATE(YEAR(__maxDate) - 1, MONTH(__maxDate), DAY(__maxDate))

RETURN
IF (
'FinancialTrans'[Date] >= __startDate &&
'FinancialTrans'[Date] <= __endDate,
1,
0
)

Then use a visual-level filter on the table to show only rows where Show SPLY Txn = 1.


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Still an issue...

I created this demo. Here's a link to the .pbix and .xlsx files: https://www.dropbox.com/scl/fi/9pagceic1e3zuidfvrcbb/DonorTest.pbix?rlkey=gwa1a2utd48q65ngkndtl8sa8&...

https://www.dropbox.com/scl/fi/02q6hm6cl5uz3s5eynu10/demo.xlsx?rlkey=zm36rhesums6dme7c4j2edv74&st=min8gt6f&dl=0

 

As you can see in the image below, while the matrix accurately displays only the total for entries within the date range for both current and sply, the table attached to SPLY Transactions Table is showing ALL the records in the month from 2023 instead of cutting off at 1/15. Effectively ignoring the filter set in the calculated table. Why??

 

Also, I tried to create the measure you suggested, but at the "IF(" point, all I get prompted are measures and when I try to add the reference to 'FinancialTrans'[Date] I get an error. 

 

2025-03-24 -DonorTest - Power BI Desktop000471.jpg2025-03-24 -DonorTest - Power BI Desktop000470.jpg

Amira,

Perfect! Thanks!

All I had to do was add another column: 

"AcntName", RELATED(Accounts[Account])  // added the Account Type for the transaction
and I had everything I needed.
Apprecitate the help.

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors