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

filter table by year and weekyear

Hello,

 

I'd like to create simple filters using a dax measure... I usually use calculated fonction...

 

CALCULATE(<expression>[, <filter1> [, <filter2> [, …]]])

 

But I just have dates and text... without other measures like sales,....

 

I have 2 tables

 

-  'text' Table

 

datetext
1/1/2019text1
2/1/2019text2
......
1/1/2020text4
12/31/2020text5

 

- Date Table

dateweek_year_noyear
O1/01/201912019
.........
31/12/2020522020

 

I would like to extract the right text from the text table according to the current week number and the year.

 

I tried

 

Text_context = CALCULATETABLE(Table,Table[ week_year_no]=WEEKNUM(TODAY())

 

or

 

Text_context = FILTER(Table,Table[ week_year_no]=WEEKNUM(TODAY())

 

 

Do you know how I could filter this table according to the year and the week number?
And generally how it's possible to apply several filters ?

 

A response would be appreciated

 

Thanks

 

Noliverte

 

1 ACCEPTED SOLUTION

Hi @noliverte ,

When I reply you the current week is 51, so you want to show data about text 50 right?

You can create a measure like this, put it in the table visual filter and set its value as 1:

A = 
IF (
    WEEKNUM ( TODAY (), 2 ) - 1
        = WEEKNUM ( SELECTEDVALUE ( 'Table'[Date] ), 2 ),
    1,
    0
)

re.png

Attached the sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

10 REPLIES 10
noliverte
Helper III
Helper III

Hi amitchandak,

 

Thanks for taking time to respond to me,

I changed my table like this

If I usenew measure = CALCULATE(countrows(Explications),filter(Calendrier,Calendrier[Week-num]=WEEKNUM(TODAY())-1))I don't have only "text week50", but all the table...

If I change in the visualization menu, I can't have only "text week50"

Do you have an idea ?

 

Have a nice day

 

Noliverte

first-last.PNG

explications-powerbi.PNG

table-explications.PNG

amitchandak
Super User
Super User

@noliverte , this should give you a new table as weeknumber is in date table

 

new table = CALCULATETABLE(Table,filter(Date,date[week_year_no]=WEEKNUM(TODAY())))

 

new measure = CALCULATE(countrows(Table),filter(Date,date[week_year_no]=WEEKNUM(TODAY())))

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

Hi amitchandak,

 

Thanks for taking time to respond to me,

I changed my table like this

table-explications.PNG

link-table.PNG

If I use

new measure = CALCULATE(countrows(Explications),filter(Calendrier,Calendrier[Week-num]=WEEKNUM(TODAY())-1))

 

I don't have "text week50"...

explications-powerbi.PNG

If I change in the visualization menu, I can't have only "text week50"

first-last.PNG

Do you have an idea ?

 

Have a nice day

 

Noliverte

Ashish_Mathur
Super User
Super User

Hi,

Against each week in the Date Table there would be 7 rows and therefore when you filter on the current week, there will be multiple text entries in the text table.  Which text entry do you want as the final result.  Please show the expected result. 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish_Mathur,

 

Thanks for taking time to respond to me, 

In my final result, I'd like to have a simple table in powerbi with the text corresponding to the number of the previous week.

 

Table : Explications

table-explications.PNG

 

link-table_LI.jpg

 

I would like to have each week the text which corresponds to the previous week.
How to build this measure?

 

(this week number is 51)

I'd like to have automatically simple text with "text week 50"

 

Have a nice day

 

Noliverte

 

 

 

Hi @noliverte ,

Not certain what is your table look like but you can try to create a measure like this:

explications =
IF (
    SELECTEDVALUE ( 'Calendar'[Weeknum] )
        = WEEKNUM ( SELECTEDVALUE ( 'Table'[Date] ), 2 ),
    "text week "
        & ( WEEKNUM ( SELECTEDVALUE ( 'Table'[Date] ), 2 ) - 1 )
)

week.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hello v-yingil,

 

Thank you for your explanation and your file, but it's not exactly what I expect.

In view report I'd like one table (without filters).report-sample.png

Table has 2 cols (date, explications)
explications isn't a measure (Data come from an Google spreadsheet file)

table.png

 

Table

table-explications.PNG

 

I would like to create a measure that would be able to display only the text (taken from the table above) from the previous week.

(if the current week number is 50, the displayed text will be "text week 49")

 

Thank you for your help and advice

 

Noliverte

Hi @noliverte ,

When I reply you the current week is 51, so you want to show data about text 50 right?

You can create a measure like this, put it in the table visual filter and set its value as 1:

A = 
IF (
    WEEKNUM ( TODAY (), 2 ) - 1
        = WEEKNUM ( SELECTEDVALUE ( 'Table'[Date] ), 2 ),
    1,
    0
)

re.png

Attached the sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi v-yingil,

Congratulation it works fine.
Thank you very much for your precious help.

I've added a if statement to fit with my final report

A = 
IF(
    YEAR(TODAY())
        = YEAR(SELECTEDVALUE('Table'[Date])),
        IF (
            WEEKNUM ( TODAY (), 2 ) - 1
                = WEEKNUM ( SELECTEDVALUE ( 'Table'[Date] ), 2 ),
            1,
            0
        ),
        0
)

One last request with your pbix.
In my final powerbi file, I have to hide the date fied to only show explanations...

Do you know how i could remove this field from my table?
In your file, if I remove this date field from the table, the explanation field also disappears

 

new-without-date.PNG

 

Have a nice day

 

Noliverte

Hi,

I just found a way to hide date field...
I replace Table viewer by HTML5 viewer

html5.PNG

And the table vs html5 component
left : Table
right : html 5 component

html5vs.PNG

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.