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
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
Employee
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
Employee
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. 

v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

@v-shex-msft 

 

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

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
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.