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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Measure with multiple dates

I want to generate the the following dates in a single measure (Yesterday, Today, last week, and This week) such that when i drag this field to a table or card it gives a list of all four as a list without me creating four measures. Thanks

 

Capture.PNG

2 ACCEPTED SOLUTIONS
mahoneypat
Microsoft Employee
Microsoft Employee

Not sure if this is what you mean, but you can get a card of those values with this one measure.  Note that there are carriage returns in the "return" part.

 

Four Dates = var thisday = TODAY()
var yesterday = thisday -1
var thisweek = thisday - WEEKDAY(thisday) +1 & " - " & thisday-WEEKDAY(thisday) + 7
var lastweek = thisday-6-WEEKDAY(thisday) & " - " & thisday-WEEKDAY(thisday)
return
"Today - " & thisday & "
Yesterday - " & yesterday & "
This Week - " & thisweek & "
Last Week - " & lastweek
 
I tried to add a pic of the card visual but pics aren't showing in my posts at the moment.
 
 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

Anonymous
Not applicable

@mahoneypat 

 

 

Thanks so much, this is what i needed. 

View solution in original post

6 REPLIES 6
mahoneypat
Microsoft Employee
Microsoft Employee

Not sure if this is what you mean, but you can get a card of those values with this one measure.  Note that there are carriage returns in the "return" part.

 

Four Dates = var thisday = TODAY()
var yesterday = thisday -1
var thisweek = thisday - WEEKDAY(thisday) +1 & " - " & thisday-WEEKDAY(thisday) + 7
var lastweek = thisday-6-WEEKDAY(thisday) & " - " & thisday-WEEKDAY(thisday)
return
"Today - " & thisday & "
Yesterday - " & yesterday & "
This Week - " & thisweek & "
Last Week - " & lastweek
 
I tried to add a pic of the card visual but pics aren't showing in my posts at the moment.
 
 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

@mahoneypat 

 

 

Thanks so much, this is what i needed. 

Anonymous
Not applicable

Hi @Anonymous,

You can't use the measure to return multiple results, it is a calculated expression based on row contents. (if you did not has any category fields, it can only one result value)

If you want this measure to return four type of calculation results, you need to create a category with these category types(Yesterday, Today, last week, and This week) and add switch function into the measure formula with different categories.
Then you can navigate to different calculation expressions based on current category value.

Measure =
VAR currCate =
    SELECTEDVALUE ( Table[Category] )
RETURN
    SWITCH (
        currCate,
        "Yesterday", 'formula1',
        "Today", 'formula2',
        "last week", 'formula3',
        "This week", 'formula4'
    )

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

@Anonymous 

 

Thanks for your response. A coule of questions though,

1) When you say categories, do you mean the actual dates for each(Today, yesterday, last week and this week)?
2) So, this is not a question but more of a correction based on my question. There is no date field so I will be using Current day as my date field, possibly Today() formula.
3) Lastly,do i need to create formula1, 2,3 and 4 too?

amitchandak
Super User
Super User

@Anonymous , Not very clear.

when we return value we can return a value only. So if you need this you need to have a series

 

table = generateseries(0,6,1)

 

measure = calculate(today() -min(Table[Value]))

On the card, this will give today date. when you use series to display it will give 7 days

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak 

 

I'm sorry if i wasn't clear. I should have mentioned that these respective dates would be generated from an existing date field.  In your solution you mentioned that if i display it with a series, it will give 7days. Not sure what you mean by that. 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.