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
SM4
New Member

Displaying columns based on user input.

I am new to power bi so please forgive me if its a simple silly solution.

 

I am working with data which has value for month-year for 2 years i.e. 24 columns, i want to creat a table/matrix wherein based on the users input of month and year all the columns till then would be displayed, for example if user input is Aug 23 all months from Jan 23 till Aug 23 should be displayed.

2 ACCEPTED SOLUTIONS
tamerj1
Super User
Super User

Hi @SM4 
Please refer to attached sample file the proposed solution

1.png2.png3.png4.png5.png6.png

View solution in original post

@SM4 

Month YTD = 
VAR Months = ALLNOBLANKROW ( 'Table'[Month Name], 'Table'[Month] )
RETURN
    GENERATE ( 
        Months,
        FILTER ( 
            SELECTCOLUMNS ( Months, "@Month", 'Table'[Month] ),
            [@Month] <= 'Table'[Month]
                && YEAR ( [@Month] ) = YEAR ( 'Table'[Month] )
        )
    )

1.png

View solution in original post

7 REPLIES 7
tamerj1
Super User
Super User

Hi @SM4 
Please refer to attached sample file the proposed solution

1.png2.png3.png4.png5.png6.png

thank you so much, it helped a lot.

 

  • Is there a way to add a year filter as well? eg. Apr 24 would show only jan 24 to apr 24 not the other year

@SM4 

Month YTD = 
VAR Months = ALLNOBLANKROW ( 'Table'[Month Name], 'Table'[Month] )
RETURN
    GENERATE ( 
        Months,
        FILTER ( 
            SELECTCOLUMNS ( Months, "@Month", 'Table'[Month] ),
            [@Month] <= 'Table'[Month]
                && YEAR ( [@Month] ) = YEAR ( 'Table'[Month] )
        )
    )

1.png

v-jtian-msft
Community Support
Community Support

 

Hi @SM4 ,

 

Thanks for the reply from @tamerj1@VishalJhaveri , please allow me to provide another insight:

 

Thanks for your concern about this case.
I noticed you sent the data link but unfortunately I don't have permission to access it.
When I try to access the data, the page shows the following:

vjtianmsft_13-1713347415344.png

I tried to create a sample data myself based on the user's requirement and implemented the result. Please check if there is anything that can be improved. Here is my solution:
The first thing I did was to create a date table with two years of time using the dax function.

Here is the dax function:

 

Table 2 = CALENDAR("2023-1-1","2024-12-31")

 

 

I then duplicated this table and now have two identical data tables

 

Table = CALENDAR("2023-1-1","2024-12-31")

 

 

vjtianmsft_14-1713347415353.png

I am creating a slicer with the table's column field with month as the filter criteria

You can add filters by year and month to the slicer clock.

vjtianmsft_15-1713347586991.png

I then used table2 to display the final results of the filter, and created a measure for table2 called "M_".
here is the dax code for ”M_

 

M_ =
VAR _Slicer =
    MAX ( 'Table'[Date] )
VAR _Slicermonth =
    MONTH ( _Slicer )
RETURN
    IF (
        MAX ( 'Table 2'[Date] ) <= _Slicer
            && YEAR ( MAX ( 'Table 2'[Date] ) ) = YEAR ( _Slicer ),
        MONTH ( MAX ( 'Table 2'[Date] ) ),
        BLANK ()
    )

 

 

vjtianmsft_16-1713347587000.png

The max function will filter out the maximum value of the current filter conditions

vjtianmsft_17-1713347696417.png

Now you can click on a month of a year in the filter to filter out data from January to the selected month of the year.

I hope my suggestions  give you good ideas, if you have any more questions, please clarify in a follow-up reply.

 

Best Regards,

Carson Jian,

 

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

tamerj1
Super User
Super User

Hi @SM4 
Please provide sample input data

VishalJhaveri
Resolver III
Resolver III

+1

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.