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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Fulfilled
Frequent Visitor

Get count of a column for every asset based off of a timestamp that's unique to each asset

Here is my problem:

 

Lets say i have 10 machines that accept bills and coupons.  Those machines have a capacity to hold 500 bills.  I want to setup a dashboard that will inform me of the bill count of each of those machines so that they dont fill up.  My data is as follows:

 

Table 1

 

Asset # (AssetID)

Transaction codes (Bill accepted, Cash Emptied) (TXCode)

  • 11 (Bill Accepted)
  • 12 (Coupon Accepted)
  • 13 (Cash Emptied)

Timestamp (TransDate)

 

Example:

 

AssetIDTXCodeTransDate
1117/1/2023 12:13pm
2117/1/2023 12:12pm
3127/1/2023 12:11pm
1137/1/2023 12:10pm
2137/1/2023 12:05pm
3137/1/2023 12:01pm

 


From this table i am able to grab a timestamp for when the cash was last emptied, hence resetting the count of bills accepted since that last event.

 

I have tried many different ways to come up with the total count of TXCodes since last "Cash Emptied" TX Code, however everything i come up with seems to lead to a memory crunch when trying to calculate it.  My latest attempt consisted of creating a 2nd table with 1 row for each Asset.  On that table i brought in the "Cash Emptied" DateTime timestamp for each asset.  I then tried to leverage that value in the following formula thinking that would be less calculations needed in the formula so maybe it would work quicker, but it led to the same result. Here is the latest DAX formula i tried as well as the info in new table i am leveraging:

 

Table 2

 

Asset # (AssetID)
Cash Emptied Timestanp (CashEmptied)

 

Table2 Example:

 

AssetIDCashEmptied
17/1/2023 12:10pm
27/1/2023 12:05pm
37/1/2023 12:01pm

 

 

=

VAR _Emptied = CALCULATE(MAX(Table2[CashEmptied]), ALLEXCEPT(Table2, Table2[AssetID]))


Return

CALCULATE(COUNT(Table1[TXCode]) , ALLEXCEPT(Table2, Table2[AssetID]) ,
KEEPFILTERS(Table1[TXCode] = "11" || Table1[TXCode] = "2" ) ,

TIME(
HOUR('Table1'[TransDate]),
MINUTE('Table1'[TransDate]),
SECOND('Table1'[TransDate])
) >= TIMEVALUE( _Emptied )
)


After this failed, i tried creating a column labeled "Inserted" in table 1 using an IF statement:

Inserted =

IF((Table1[TXCode] = "11") || (Table1[TXCode] = "12") , 1 , 0)


I figured i would remove the "filter" aspect out of the query itself again to try and minimize the calculations needed in the single query to hopefully avoid the memory crunch issue. I then tried to SUM up all the values in the Inserted column after the "CashEmptied" associted with each asset. This was my query:

=

VAR _Emptied = CALCULATE(MAX(Table2[CashEmptied]), ALLEXCEPT(Table2, Table2[AssetID]))


Return

CALCULATE(SUM(Table1[TXCode]) , ALLEXCEPT(Table2, Table2[AssetID]) ,

TIME(
HOUR('Table1'[TransDate]),
MINUTE('Table1'[TransDate]),
SECOND('Table1'[TransDate])
) >= TIMEVALUE( _Emptied ),

)

However i ran into the same issue with memory. At this point i am unsure how to accomplish this query in an efficient way to achieve my goal. Was hoping someone could help me rework my certainly poor DAX formula to give me a solution to this problem. I appreciate your help in advance!!

1 REPLY 1
johnt75
Super User
Super User

Try

Num bills =
IF (
    ISINSCOPE ( 'Table'[AssetID] ),
    VAR CurrentAsset =
        SELECTEDVALUE ( 'Table'[AssetID] )
    VAR LastEmptied =
        CALCULATE ( MAX ( 'Table'[Trans date] ), 'Table'[TX Code] = 13 )
    VAR Result =
        CALCULATE (
            COUNTROWS ( 'Table' ),
            'Table'[TX Code] IN { 11, 12 },
            'Table'[Trans date] > LastEmptied
        )
    RETURN
        Result
)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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