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
matrix_user
Helper III
Helper III

Count the latest week of data available.

Hello DAXers,

 

I am in a situation where I cannot get my visual card to show the correct/latest week of data avaiable in my model. 

 

To present my data in a visual card I am currently using the following DAX expression:

 

Latest week count =

VAR Count = MAX('Date'[WeekNbrYear])RETURN

CALCULATE(COUNT('Fact Table'[Entry_date]),('Date'[WeekNbrYear] = Count))

 

The "('Fact Table'[Entry_date])" are dates customers have purchased from a store. The data type for this calculated column is set to Date: 14/03/01(d/mm/yy). I want to count each entry date and represent it in a visual card and for it to display only the latest week - be it a full 7 days (Monday to Sunday) or a couple of days (Mon to Tues).

 

I have no problems displaying card counts for the last day or month available in my model - using the above DAX expression with appropriate modifications for day and month. 

 

My week is from Monday to Sunday.

 

Time intelligence is on (I tried both on and off).

 

The 'Date'[WeekNbrYear] is a calculated column from my date table. Data type is text and ranges from Monday to Sunday:

 

WeekNbrYear = "W" & WEEKNUM ('Date'[Date],2) & " - " & YEAR ([Date])

 

The below visual shows data for 2022 BUT the visual Card showing 1282 customers (W9-2022) instead of the latest being 356.

 

matrix_user_1-1657928838018.png

 

What am I doing wrong?

1 ACCEPTED SOLUTION

Not sure what you are saying... do you mean I should change my current DAX expression to:

 

Count =  calculate(MAX('Date'[WeekNbrYear]),all(table)),

CALCULATE(COUNT('Fact Table'[Entry_date]),('Date'[WeekNbrYear] = Count))

 

...because that doen't work.

View solution in original post

6 REPLIES 6
v-zhangti
Community Support
Community Support

Hi, @matrix_user 

 

Can you provide some sample data or simple pbix files? Sensitive information can be removed in advance.

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

vapid128
Solution Specialist
Solution Specialist

Try this

 

VAR Count =

 

 

CALCULATE(

COUNT('Fact Table'[Entry_date]),

FILTER(All('Fact Table'),'Date'[WeekNbrYear] = MAX('Date'[WeekNbrYear]))
)

Hello,
 
Still not quiet working.  The 'WeekNbr_Year" is greyed out and an error message is saying something along the lines of needing an aggreagtion.
 
Weekly count = CALCULATE(COUNT('Fact Table'[Entry_date]),
FILTER(ALL('Fact Table'),'Date'[WeekNbr_Year] = MAX('Date'[WeekNbr_Year])))
 A single value for column 'WeekNbr_Year' in table 'Date' cannot be detewrmined. This can happen when a measure formula refers to a column that contains amny values without specifying an aggregation such as min,max,count, or sum to get a single result.
matrix_user_0-1657941675512.png

 

OK,

 

Make a [wwekNbr_year] colnum in fact table,

 

Weekly count = CALCULATE(COUNT('Fact Table'[Entry_date]),
FILTER(ALL('Fact Table'),'Fact Table'[WeekNbr_Year] = MAX('Fact Table'[WeekNbr_Year])))
vapid128
Solution Specialist
Solution Specialist

Latest week count =

VAR Count = MAX('Date'[WeekNbrYear])RETURN

CALCULATE(COUNT('Fact Table'[Entry_date]),('Date'[WeekNbrYear] = Count))

 

VAR Count = MAX('Date'[WeekNbrYear])

means the max number of whatever you select

if you want the max number without any select, 

VAR Count =  calculate(MAX('Date'[WeekNbrYear]),all(table))

Not sure what you are saying... do you mean I should change my current DAX expression to:

 

Count =  calculate(MAX('Date'[WeekNbrYear]),all(table)),

CALCULATE(COUNT('Fact Table'[Entry_date]),('Date'[WeekNbrYear] = Count))

 

...because that doen't work.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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