Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Sum column values based on another column

Hi

 

I have a logging tool that reports me these column in the table "IMPORT"

[date][time][table][rows loaded]

 

So for example

01/10/2018 - 16:30 - table x - 100

01/10/2018 - 16:30 - table y - 250

 

So when I want to have the amount of rows loaded on a certain date, it's fairly easy with a visual.

 

I have then this visual

table   |  Last Import

table x |   100

table y |   250

TOTAL  |  350

Works fine

 

However, sometimes the importin runs twice so I have things like

01/10/2018 - 16:30 - table x - 100

01/10/2018 - 16:40 - table x - 120

01/10/2018 - 16:30 - table y - 250

01/10/2018 - 16:40 - table y - 257

 

In cases like this I would like to have, in the report only the rows where the date is the max, given a certain date.

 

So I wrote this DAX:

 

Last Import = SUMx(filter('Import';max('Import'[time]));'Import'[rows])

 

My concept is: filter my table import on the max value of import[time] and sum the [rows].

 

Now this works EXCEPT for the total, so I have something like

 

table   |  Last Import

table x |   120

table y |   257

TOTAL  |  727

 

It's like the measure is not filtered on the total row

 

What am I doing wrong? Thanks

 

 

  • Anonymous's avatar
    Anonymous
    7 years ago

     Hi,

     

    Try using this formula to create a calculated column and use this new calculated column for your purpose.

     

     

    LastLoadedRowCount = IF('Import'[Time]=MAXX(FILTER(ALL('Import'),EARLIER('Import'[Table])='Import'[Table] && EARLIER('Import'[Date])='Import'[Date]),'Import'[Time]),1,0) *'Import'[RowsLoaded]

     

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

     Hi,

     

    Try using this formula to create a calculated column and use this new calculated column for your purpose.

     

     

    LastLoadedRowCount = IF('Import'[Time]=MAXX(FILTER(ALL('Import'),EARLIER('Import'[Table])='Import'[Table] && EARLIER('Import'[Date])='Import'[Date]),'Import'[Time]),1,0) *'Import'[RowsLoaded]

     

    • Anonymous's avatar
      Anonymous
      Not applicable
      Hi
      Indeed it does work. However having a calculated column is memory intensive and I wanted to have it as a measure (also because I'm learning dax and trying to make it work)
  • PattemManohar's avatar
    PattemManohar
    Community Champion

    Anonymous Could you please try with a simple "Table" visual, having TableName and Rows field as values... It should work fine, as you have all fields in single table that are required, also you can have a date slicer to select a particular date as well.

     

    Not sure, why you are using DAX expressions for this

     

    • Anonymous's avatar
      Anonymous
      Not applicable
      Hi and thanks

      Because I don't want 727. The table x, for a certain date, has 2 rows and if I do it that way it will report the sum of the two rows. Instead I want only the row where the time is max (i.e. The latest log line)