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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Joaomatos2002
Frequent Visitor

STATUS HISTORY RANGE TIME

Good afternoon,

At the moment, I am working on a report and encountered a challenge. I have a table that shows the status change history for various cards over time. A card can be blocked multiple times and can also be reactivated multiple times after being blocked. My goal is to navigate through this historical table. For example, a card has been active since January, but in March it became blocked. When I select the month of February, this card will be shown as active, but when I select the month of October, it will appear as blocked. This applies to multiple cards because my aim is to calculate both the total and cumulative totals of cards in an active status or any other selected status (depending on the analysis) from the beginning of the data up to the selected month. This is possible thanks to the saved history. The purpose of this is to understand the status of cards over time when selecting different dates.

I will send a sample table of the data.

 

clientCARD_NUMberdatevaluenewvalue olddate/time
1CARNUMBER09/10/2024ACTIVOBLOQ_DM09/10/2024 10:35
1CARNUMBER07/10/2024BLOQ_DMACTIVO07/10/2024 10:40
1CARNUMBER25/09/2024BLOQ_DMACTIVO25/09/2024 18:11
1CARNUMBER20/09/2024ACTIVOBLOQ_DM20/09/2024 10:05
1CARNUMBER19/09/2024BLOQ_DMACTIVO19/09/2024 17:13
1CARNUMBER05/09/2024BLOQ_DMBLOQ_LC05/09/2024 17:34
1CARNUMBER04/09/2024BLOQ_LCACTIVO04/09/2024 10:01
1CARNUMBER14/08/2024BLOQ_DMACTIVO14/08/2024 17:42
1CARNUMBER19/07/2024ACTIVOBLOQ_DM19/07/2024 10:05
2CARNUMBER318/07/2024BLOQ_DMACTIVO18/07/2024 16:31
2CARNUMBER310/07/2024ACTIVOBLOQ_DM10/07/2024 10:05
2CARNUMBER308/07/2024BLOQ_DMACTIVO08/07/2024 17:27
2CARNUMBER321/06/2024ACTIVOBLOQ_DM21/06/2024 11:05
2CARNUMBER314/06/2024ACTIVOBLOQ_DM14/06/2024 10:05
2CARNUMBER313/06/2024BLOQ_DMACTIVO13/06/2024 19:04
2CARNUMBER312/06/2024ACTIVOBLOQ_DM12/06/2024 09:35
2CARNUMBER314/06/2023ACTIVOENVIADO14/06/2023 17:48
2CARNUMBER302/06/2023ENVIADOPROCESS02/06/2023 12:45
2CARNUMBER301/06/2023PROCESSPEDIDO01/06/2023 08:55


How can I achieve this result?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Joaomatos2002 ,

Thanks for your feedback. Please update the formula of measure [TotalCards] as below and check if it can return the expected result...

TotalCards = 
VAR CardStatusTable =
    ADDCOLUMNS (
        SUMMARIZE ( 'Tabela_B', 'Tabela_B'[CARD_NUM] ),
        "LastStatus", [CardStatusAsOfSelectedDate],
        "LastDate", [LastCreatedOnAsOfSelectedDate]
    )
VAR _lastdate =
    MAXX ( CardStatusTable, [LastDate] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Tabela_B'[CARD_NUM] ),
        FILTER (
            ALLSELECTED ( 'Tabela_B' ),
            'Tabela_B'[CREATEDATE] <= SELECTEDVALUE ( 'DateTable'[Date] )
                && 'Tabela_B'[CREATEDATE] = _lastdate
                && NOT ( 'Tabela_B'[VALUE_NEW] IN { "PED_REJECT", "CANCELADO", "" } )
        )
    )

If the above one can't help you figure out, please provide more raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

5 REPLIES 5
FarhanJeelani
Super User
Super User

To achieve a dynamic report that tracks the status of each card at any given point in time in Power BI, you can follow these steps. The key is to create a calculated column or measure that identifies the status of each card as of the selected date.

 

Here’s a step-by-step guide to setting it up:

Step 1: Create a Calendar Table
1. Create a Date table if you don’t have one. It should cover the entire range of dates in your dataset.
2. Make sure it has a column for month and year to allow you to filter by month.

Here’s a DAX formula to create the Date table:
DAX

DateTable =
ADDCOLUMNS(
CALENDAR(MIN(YourTable[date]), MAX(YourTable[date])),
"Year", YEAR([Date]),
"Month", MONTH([Date]),
"MonthName", FORMAT([Date], "MMM"),
"Year-Month", FORMAT([Date], "YYYY-MM")
)



Replace `YourTable[date]` with the actual date column in your history table.

 

Step 2: Link the Calendar Table to Your Data Table
1. Go to the Model View in Power BI.
2. Create a relationship between the `DateTable`’s `[Date]` column and your history table’s `[date]` column.
3. Set the relationship as Many-to-One and Single Directional (from `DateTable` to your table).

 

Step 3: Create a Measure to Identify the Status as of the Selected Date
Use the `LASTNONBLANK` function to get the latest status before or on the selected date. This measure will check the last available status in history up to the selected date for each card.

DAX

CardStatusAsOfSelectedDate =
VAR SelectedDate = MAX(DateTable[Date])
RETURN
CALCULATE(
LASTNONBLANKVALUE(YourTable[valuenew], [valuenew]),
FILTER(
YourTable,
YourTable[CARD_NUMber] = SELECTEDVALUE(YourTable[CARD_NUMber]) &&
YourTable[date] <= SelectedDate
)
)



This measure will dynamically return the latest status up to the selected date for each card.

Step 4: Create Measures for Total and Cumulative Counts
1. Total Count of Active Cards:
This measure calculates the total number of cards in "ACTIVO" status as of the selected date.
DAX

TotalActiveCards =
CALCULATE(
COUNTROWS(YourTable),
FILTER(
YourTable,
[CardStatusAsOfSelectedDate] = "ACTIVO"
)
)



2. Cumulative Total of Active Cards:
This measure calculates the cumulative count of cards that were ever active up to the selected date.
DAX

CumulativeActiveCards =
CALCULATE(
COUNTROWS(YourTable),
FILTER(
ALL(DateTable),
DateTable[Date] <= MAX(DateTable[Date]) &&
[CardStatusAsOfSelectedDate] = "ACTIVO"
)
)

 

Step 5: Build the Report
1. Add a slicer for `DateTable[Date]` so that you can select any date.
2. Use a Matrix or Table visual to display `CARD_NUMber` and the `[CardStatusAsOfSelectedDate]` measure to see the status of each card at the selected date.
3. Add a Card Visual or KPI to display `TotalActiveCards` and `CumulativeActiveCards` for dynamic counts based on the date selection.

This setup will give you a dynamic view of each card’s status history over time, and you can adjust the date slicer to see the status for any month or cumulative total.

If you have any further customization needs, feel free to ask!

Thank you for your time.
step1, step2 : check
Step 3:

What I want is the latest stats for each card up to a selected date. If I set a date range from 01-01-2024 to 05-11-2024, it should display only the most recent stats of each card, regardless of when that last update was (even if it was, for example, in March). When I add records to a table, it currently shows all stats for each card, which it shouldn't. I only need the most recent stats for each card.

Step 4:

  1. The code works, but it's retrieving all statuses for each card and counting them. For example, if a card has had 150 stats updates, when I filter the report for that card, the total count of cards should be 1, not 150 as it is now.
  2. I would like the cumulative total of active stats within the date range, as the tables should update based on this time interval filter.

 

Anonymous
Not applicable

Hi @Joaomatos2002 ,

Please update the formula of measure as below and check if it can return the expected result.

Measure =
VAR _date =
    SELECTEDVALUE ( 'Date'[date] )
VAR _tab =
    SUMMARIZE (
        'Table',
        'Table'[CARD_NUMber],
        "@maxdate",
            CALCULATE (
                MAX ( 'Table'[date] ),
                FILTER ( 'Table', 'Table'[CARD_NUMber] = EARLIER ( 'Table'[CARD_NUMber] ) )
            )
    )
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[CARD_NUMber] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[CARD_NUMber] = MAXX ( _tab, [CARD_NUMber] )
                && 'Table'[date] <= _date
                && 'Table'[date] <= MAXX ( _tab, [@maxdate] )
        )
    )
RETURN
    COUNTROWS ( _tab )

If the above one can't help you figure out, please provide more raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Thanks for your time...
I apologize for the delay.... but I finally managed to do what I wanted, I had to adjust some things in the codes...
Here are the codes I changed and adjusted.

 

CardStatusAsOfSelectedDate = 
VAR SelectedDate = MAX('DateTable'[Date])  -- Define a data selecionada
RETURN
CALCULATE(
    LASTNONBLANKVALUE( 
        'Tabela_B'[VALUE_NEW], 
        MAX('Tabela_B'[VALUE_NEW])
    ),
    FILTER(
        'Tabela_B',
        'Tabela_B'[CARD_NUM] = SELECTEDVALUE('Tabela_B'[CARD_NUM]) &&
        'Tabela_B'[CREATEDATE] <= SelectedDate
    )
)

 

In the same way that I went to get the last status, I also chose to go to the last date:

 

LastCreatedOnAsOfSelectedDate = 
VAR SelectedDate = MAX('DateTable'[Date])
RETURN
CALCULATE(
    MAX('Tabela_B'[CREATEDATE]),
    FILTER(
        'Tabela_B',
        'Tabela_B'[CARD_NUM] = SELECTEDVALUE('Tabela_B'[CARD_NUM]) &&
        'Tabela_B'[CREATEDATE] <= SelectedDate
    )
)

 

I use both to calculate the total number of cards:  

 

TotalCards = 
VAR CardStatusTable =
    ADDCOLUMNS(
        SUMMARIZE(
            'Tabela_B',
            'Tabela_B'[CARD_NUM]
        ),
        "LastStatus", [CardStatusAsOfSelectedDate],
        "LastDate", [LastCreatedOnAsOfSelectedDate]
    )
RETURN
CALCULATE(
    COUNTROWS(CardStatusTable),
    FILTER(
        CardStatusTable,
        [LastStatus] <> "PED_REJECT" &&
        [LastStatus] <> "CANCELADO" &&
        [LastStatus] <> ""
    )
)

 

 

The only thing I couldn't do was the "accumulated", that is, when I present the measure in the matrix table, the data that should be presented should count from the beginning of the data entry to the current line of the matrix, to have a notion of the evolution over time. 

If you think I'm doing something wrong, I would appreciate it if you could also give me some tips!!

If anyone can give a hint in this code that I am missing, I would appreciate it...

Anonymous
Not applicable

Hi @Joaomatos2002 ,

Thanks for your feedback. Please update the formula of measure [TotalCards] as below and check if it can return the expected result...

TotalCards = 
VAR CardStatusTable =
    ADDCOLUMNS (
        SUMMARIZE ( 'Tabela_B', 'Tabela_B'[CARD_NUM] ),
        "LastStatus", [CardStatusAsOfSelectedDate],
        "LastDate", [LastCreatedOnAsOfSelectedDate]
    )
VAR _lastdate =
    MAXX ( CardStatusTable, [LastDate] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Tabela_B'[CARD_NUM] ),
        FILTER (
            ALLSELECTED ( 'Tabela_B' ),
            'Tabela_B'[CREATEDATE] <= SELECTEDVALUE ( 'DateTable'[Date] )
                && 'Tabela_B'[CREATEDATE] = _lastdate
                && NOT ( 'Tabela_B'[VALUE_NEW] IN { "PED_REJECT", "CANCELADO", "" } )
        )
    )

If the above one can't help you figure out, please provide more raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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