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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
toum
Helper I
Helper I

CurrentGroupBY error

Spoiler

Hello all,
Please can someone help me with this, I've spent a week on this but my code does not work:

'''

N = SUMX(GROUPBY(FILTER(tab, tab[VDate] <= MAX('Date_Table'[date])), tab[pid], "max_date", MAX(tab[VDate])), SUMX(FILTER(tab, tab[pid] = CURRENTGROUP()[pid] && tab[VDate] = CURRENTGROUP()["max_date"]), tab[qty]))

'''

the ["max_date"] and [pid] are in red Unexpected expression

  1. First, filter the table to only include rows where the date column is less than or equal to the maximum date selected in the slicer. This can be done using the FILTER function and the MIN and MAX functions from the slicer table.
  2. Next, group the filtered table by the "name" column using the GROUPBY function, and create a new column "max_date" that holds the maximum date for each group.
  3. Then, use the SUMX function to sum the QTY column for each group where the date column of that row is equal to the max_date of that group
 

 

2 ACCEPTED SOLUTIONS
v-jingzhang
Community Support
Community Support

Hi @toum 

 

If I understand it correctly and if your final expected result is a new table, you can try below DAX to create a new table. 

New Table = 
var __minDate = MIN('Date'[Date])
var __maxDate = MAX('Date'[Date])
var __table = SUMMARIZE(FILTER('Table','Table'[vdate]<=__maxDate && 'Table'[vdate]>= __minDate),'Table'[pid],"max_date",MAX('Table'[vdate]))
return
ADDCOLUMNS(__table,"total_qty",SUMX(FILTER('Table','Table'[pid]=[pid] && 'Table'[vdate]=[max_date]),'Table'[qty]))

vjingzhang_0-1674094308599.png

 

If your expected result is a measure, you can try 

Measure = 
var __minDate = MIN('Date'[Date])
var __maxDate = MAX('Date'[Date])
var __table = SUMMARIZE(FILTER('Table','Table'[vdate]<=__maxDate && 'Table'[vdate]>= __minDate),'Table'[pid],"max_date",MAX('Table'[vdate]))
var __table2 = ADDCOLUMNS(__table,"total_qty",SUMX(FILTER('Table','Table'[pid]=[pid] && 'Table'[vdate]=[max_date]),'Table'[qty]))
return
SUMX(__table2,[total_qty])

vjingzhang_1-1674094767664.png

 

I used SUMMARIZE instead of GroupBy. The sample file has been attached at bottom including above two examples. 

 

If this is not what you want, can you please provide some sample data with the necessary columns VDate, pid, qty in table format as well as the expected result based on the sample data? This could help us understand the problem and provide a possible solution faster. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

Hi @toum Sorry I forgot to attach the sample file in previous reply. Please find it in this reply. 

View solution in original post

3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @toum 

 

If I understand it correctly and if your final expected result is a new table, you can try below DAX to create a new table. 

New Table = 
var __minDate = MIN('Date'[Date])
var __maxDate = MAX('Date'[Date])
var __table = SUMMARIZE(FILTER('Table','Table'[vdate]<=__maxDate && 'Table'[vdate]>= __minDate),'Table'[pid],"max_date",MAX('Table'[vdate]))
return
ADDCOLUMNS(__table,"total_qty",SUMX(FILTER('Table','Table'[pid]=[pid] && 'Table'[vdate]=[max_date]),'Table'[qty]))

vjingzhang_0-1674094308599.png

 

If your expected result is a measure, you can try 

Measure = 
var __minDate = MIN('Date'[Date])
var __maxDate = MAX('Date'[Date])
var __table = SUMMARIZE(FILTER('Table','Table'[vdate]<=__maxDate && 'Table'[vdate]>= __minDate),'Table'[pid],"max_date",MAX('Table'[vdate]))
var __table2 = ADDCOLUMNS(__table,"total_qty",SUMX(FILTER('Table','Table'[pid]=[pid] && 'Table'[vdate]=[max_date]),'Table'[qty]))
return
SUMX(__table2,[total_qty])

vjingzhang_1-1674094767664.png

 

I used SUMMARIZE instead of GroupBy. The sample file has been attached at bottom including above two examples. 

 

If this is not what you want, can you please provide some sample data with the necessary columns VDate, pid, qty in table format as well as the expected result based on the sample data? This could help us understand the problem and provide a possible solution faster. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Hi @toum Sorry I forgot to attach the sample file in previous reply. Please find it in this reply. 

Thank you a lot for your help

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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