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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mallikarjuna_n
New Member

Select all records less than the given month

Hi,

 

I have table where having PERIOD_MMYY as MMYY along with other columns. my entair model is filtering on this PERIOD_MMYY column

if the user select a period PERIOD_MMYY from slicer then my vizualization table should show all the data for the given year and less or equal to given Month.

Is there any way to store our slicer value in a variable so it can be used in filter?

else any soluntion for this?

Example:

PERIOD_MMYYCol1Cal2
0123  
0223  
0323  
0423  
0523  
0623  
0723  
0823  
0923  
1023  
1123  
1223  
0124  
0224  
0324  
0424  
0524  
0624  
0724  
0824  
0924  

 

scenario1: user selected in slicer : 0523

Expected:

 

PERIOD_MMYYCol1Cal2
0123  
0223  
0323  
0423  
0523  

 

scenario2: user selected as 0824

Then expected is:

PERIOD_MMYYCol1Cal2
0124  
0224  
0324  
0424  
0524  
0624  
0724  
0824  

 

FYI .. each month can have multiple records.

 

Thank you in Advance.

 

 

 

 

1 ACCEPTED SOLUTION

Hi, @mallikarjuna_n 

What should I do with the null value corresponding to your field BOOK_PERIOD_YY? Are the nulls removed, or are they supposed to occur in what context?


I do not handle null values in the following method.


First you need New Column to convert the field BOOK_PERIOD_YY to the following form:

vfenlingmsft_0-1726036126252.png

FormattedPeriod = 
VAR YearPart = RIGHT ( Table1[BOOK_PERIOD_YY], 2 )
VAR MonthPart = MID ( Table1[BOOK_PERIOD_YY], 1, LEN(Table1[BOOK_PERIOD_YY]) - 2 )
RETURN
    IF (
        LEN(MonthPart) < 2 && NOT ISBLANK(MonthPart),
        "0" & MonthPart & YearPart,
        Table1[BOOK_PERIOD_YY]
    )


Then New Table:

vfenlingmsft_1-1726036171039.png

Table2 = SELECTCOLUMNS(Table1,"FormattedPeriod",Table1[FormattedPeriod])


Remember not to link the newly created table to other tables:

vfenlingmsft_2-1726036245004.png


Then New Measure:

FilterDate = 
VAR selectPeriod = SELECTEDVALUE ( Table2[FormattedPeriod] )
VAR selectMonth = LEFT ( selectPeriod, 2 )
VAR selectYear = RIGHT ( selectPeriod, 2 )
VAR CurrentMonth = LEFT ( MAX ( Table1[FormattedPeriod] ), 2 )
VAR CurrentYear = RIGHT ( MAX ( Table1[FormattedPeriod] ), 2 )
RETURN
    IF (
        ISBLANK(selectPeriod),
        1,
        IF ( VALUE(CurrentYear) = VALUE(selectYear) && VALUE(CurrentMonth) <= VALUE(selectMonth), 1, 0 )
    )


Finally drag Measure to the Filter panel and set Measure to 1 to show only rows with Measure of 1:

vfenlingmsft_3-1726036349966.png

 

vfenlingmsft_4-1726036393101.png

 

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
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

8 REPLIES 8
v-fenling-msft
Community Support
Community Support

Hi, @mallikarjuna_n 

May I ask what your specific data looks like?


Since you didn't give specific data for testing, I assumed some data for testing myself:

vfenlingmsft_0-1725599628626.png

 

My PERIOD_MMYY is a Date type, so I went through Custom Column in Power Query Editor and created a new column to convert PERIOD_MMYY1 to Month+Year to match your data:

vfenlingmsft_1-1725599708097.png

 

Text.PadStart(Text.From(Date.Month([PERIOD_MMYY])), 2, "0") & Text.End(Text.From(Date.Year([PERIOD_MMYY])), 2)

Then New table, created a table for Slicer to filter PERIOD_MMYY:

vfenlingmsft_3-1725599805036.png

 

Table2 =
SELECTCOLUMNS (
    Table1,
    "PERIOD_MMYY", Table1[PERIOD_MMYY],
    "PERIOD_MMYY1", Table1[PERIOD_MMYY1]
)

Then created a Measure, dragged the Measure to the Filters panel set the Measure to 1 to filter the data:

FilterDate =
VAR selectPeriod =
    SELECTEDVALUE ( Table2[PERIOD_MMYY1] )
VAR selectMonth =
    LEFT ( selectPeriod, 2 )
VAR selectYear =
    RIGHT ( selectPeriod, 2 )
VAR CurrentMonth =
    LEFT ( MAX ( Table1[PERIOD_MMYY1] ), 2 )
VAR CurrentYear =
    RIGHT ( MAX ( Table1[PERIOD_MMYY1] ), 2 )
RETURN
    IF ( CurrentYear = selectYear && CurrentMonth <= selectMonth, 1, 0 )

vfenlingmsft_4-1725599928516.png

vfenlingmsft_5-1725599982387.png

 

I have attached the pbix file for this example below, hope this helps.

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi,

Thank you for your reply...

as you requested below is the sample data(not got option to upload) along with this table there are 5 other tables which are joining on different columns but  some tables have book period. In this table the book period is a string not date type.

 

FILE_IDSOURCE_IDFILE_STATUSBOOK_PERIOD_YYRECEIVED_DATECMNTCREATED_DATE
27INComplete 14-Jun-24 14-Jun-24
26PKRequest To Unload62410-Jun-24test10-Jun-24
25PKReprocess Errors62406-Jun-24testing DB file to check asdf06-Jun-24
24PKComplete52413-May-24 13-May-24
23INComplete52413-May-24 13-May-24
22PKDeleted52406-May-24File was sent with amount different to wire received.  New file received from Alight.06-May-24
21INComplete52403-May-24 03-May-24
20INComplete42402-May-24Load amount from payroll.02-May-24
19INDeleted52401-May-24Incorrect amount was processed.01-May-24
18INComplete42417-Apr-24 17-Apr-24
17PKComplete42405-Apr-24bmdoiejm,dddsfadfasf05-Apr-24
16INComplete32402-Apr-24asdfsadfasfoiuweo 02-Apr-24
15INComplete42401-Apr-24oieuropihvadsf01-Apr-24
14PKComplete32414-Mar-24Upload of February Direct Bill 14-Mar-24
13INComplete32413-Mar-24Load oiwquriohoadjhv13-Mar-24
12INDeleted32411-Mar-24received new file11-Mar-24
11PKDeleted32405-Mar-24new file received05-Mar-24
10INReady To Process22404-Mar-24test04-Mar-24
9INPassed Edits32401-Mar-24load01-Mar-24
8PKComplete22427-Feb-24load Jan DB file27-Feb-24
7PKDeleted22427-Feb-24delete27-Feb-24
6INComplete22415-Feb-24load 2nd source file15-Feb-24
5PKDeleted22405-Feb-24delete05-Feb-24
4INComplete12402-Feb-24load INernal contr02-Feb-24
3INRequest To Unload22401-Feb-24test01-Feb-24
2INNew File 04-Jan-24 04-Jan-24
1INPassed Edits12403-Jan-24Process Jan amount03-Jan-24

Hi, @mallikarjuna_n 

What should I do with the null value corresponding to your field BOOK_PERIOD_YY? Are the nulls removed, or are they supposed to occur in what context?


I do not handle null values in the following method.


First you need New Column to convert the field BOOK_PERIOD_YY to the following form:

vfenlingmsft_0-1726036126252.png

FormattedPeriod = 
VAR YearPart = RIGHT ( Table1[BOOK_PERIOD_YY], 2 )
VAR MonthPart = MID ( Table1[BOOK_PERIOD_YY], 1, LEN(Table1[BOOK_PERIOD_YY]) - 2 )
RETURN
    IF (
        LEN(MonthPart) < 2 && NOT ISBLANK(MonthPart),
        "0" & MonthPart & YearPart,
        Table1[BOOK_PERIOD_YY]
    )


Then New Table:

vfenlingmsft_1-1726036171039.png

Table2 = SELECTCOLUMNS(Table1,"FormattedPeriod",Table1[FormattedPeriod])


Remember not to link the newly created table to other tables:

vfenlingmsft_2-1726036245004.png


Then New Measure:

FilterDate = 
VAR selectPeriod = SELECTEDVALUE ( Table2[FormattedPeriod] )
VAR selectMonth = LEFT ( selectPeriod, 2 )
VAR selectYear = RIGHT ( selectPeriod, 2 )
VAR CurrentMonth = LEFT ( MAX ( Table1[FormattedPeriod] ), 2 )
VAR CurrentYear = RIGHT ( MAX ( Table1[FormattedPeriod] ), 2 )
RETURN
    IF (
        ISBLANK(selectPeriod),
        1,
        IF ( VALUE(CurrentYear) = VALUE(selectYear) && VALUE(CurrentMonth) <= VALUE(selectMonth), 1, 0 )
    )


Finally drag Measure to the Filter panel and set Measure to 1 to show only rows with Measure of 1:

vfenlingmsft_3-1726036349966.png

 

vfenlingmsft_4-1726036393101.png

 

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-fenling-msft 

 

I want to apply same slicer for all the other pages (5 pages), in this case do I need to do any setting at filter level?

 

I did synchronization setting for all pages but seems its not applying.

plz suggest me if I need to do any settings.

 

Best Regards,

Mallikarjuna N

Hi, @mallikarjunan 

What specific data do you need to filter?


Let's say the data on the other page is the same as page 1:

vfenlingmsft_1-1726650567890.png

 

vfenlingmsft_2-1726650588156.png

 

You need to set FilterDate to 1 in the Filter panel of the other pages:

vfenlingmsft_3-1726650621248.png

 


Also you need to enable this feature, then select the corresponding page to apply this Slicer too:

vfenlingmsft_4-1726650680438.png

 

This is the official documentation about Slicer, hope it will help you:

Slicers in Power BI - Power BI | Microsoft Learn

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you somuch @v-fenling-msft it worked.

Hi, @mallikarjunan 

It looks like you have found a solution. Could you please mark this helpful post as “Solution”?

 

This will help others in the community to easily find a solution if they are experiencing the same problem as you.

 

Thank you for your cooperation!

 

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Shravan133
Solution Sage
Solution Sage

Try this: FilteredData =
VAR SelectedPeriod = SELECTEDVALUE('YourTable'[PERIOD_MMYY])
VAR SelectedYear = RIGHT(SelectedPeriod, 2)
VAR SelectedMonth = LEFT(SelectedPeriod, 2)
RETURN
CALCULATE(
SUM('YourTable'[Col1]), -- Or use whatever calculation is appropriate for your table
FILTER(
'YourTable',
RIGHT('YourTable'[PERIOD_MMYY], 2) = SelectedYear &&
VALUE(LEFT('YourTable'[PERIOD_MMYY], 2)) <= VALUE(SelectedMonth)
)
)

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.