March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
Hi All,
I need help to Dynamically select columns in table visual.
My requirement is we have data in columns like Sep-23, Oct-23, Nov-23, Dec-23, Jan-24, Feb-24, Mar-24, Apr-24, May-24, Jun-24, Jul-24, Aug-24. for 12 months data. For next month Sep-23 will remove automatically and Oct-24 month data need to add in table visual automatically
And also it has to sum all 12 months data automatically for next month.
I tried unpivot columns option but it is not working.
Below is the sample data set for your reference.
The columns are not dynamically changeable in table visual as these are the parameters that are added to the visual. What can be done for a small data is to transpose the data. This will make products as column and month as rows. Now, make a measure of each product and month.
For transpose,
1) Make header the first row
2) Transpose[Transform in Power Query -> Transpose]
3) Make first Row as headers
Revised Answer:
To dynamically select columns in a table visual and automatically handle the addition and removal of columns based on your requirements, you can achieve this in Power BI by using DAX expressions and data modeling. Here's a step-by-step guide on how to do it:
Data Preparation:
Data Modeling:
Use Dax:
Display Month Flag =
IF(
AND(
[Date] >= TODAY(),
[Date] < TODAY() + 365,
MONTH([Date]) <= MONTH(TODAY()) + 12
),
1,
0
)
This calculated column will evaluate to 1 for the 12 months starting from the current month and 0 for other months.
Table Visual:
Visual-Level Filter:
Now, your table visual should dynamically display the data for the current month plus the next 11 months, automatically removing the oldest month as time progresses.
Additionally, to automatically sum the data for the displayed 12 months, you can use another DAX measure:
Use Dax:
Total 12 Months Value = SUMX(FILTER('YourData', [Display Month Flag] = 1), 'YourData'[Value])
You can place this measure in your table visual, and it will show the sum of the displayed 12 months' data.
Remember to replace 'YourData' with the name of your actual data table.
By following these steps and creating calculated columns and measures based on the "Display Month Flag," you can achieve the dynamic column selection and summation in your table visual as per your requirements.
and
If you want to dynamically change the columns in a table visual based on your data and have products as columns and months as rows, you can indeed use the Power Query's Transpose feature. Here's how you can do it:
Data Preparation:
Power Query (Data Transformation):
Data Modeling in Power BI:
Measures:
Use Dax:
Total_Sep_23 = SUM('YourTable'[Sep-23])
Total_Oct_23 = SUM('YourTable'[Oct-23])
-- Repeat for all months
Replace 'YourTable' with the actual name of your table.
Table Visual:
With this approach, your table visual will dynamically show columns for each product and rows for each month, and the data will be aggregated according to the measures you created. As you add new data for future months, you won't need to manually adjust the columns in the visual; they will adapt automatically based on your transposed data structure.
If I answered your question, please mark my post as solution, Appreciate your Kudos.
To dynamically select columns in a table visual in Power BI based on your requirements, you can follow these steps:
Data Preparation: Ensure your data is in a format that's conducive to dynamic column selection. You should have columns for the month name and corresponding data. If your data currently looks like this:
Sep-23 Oct-23 Nov-23 Dec-23 Jan-24 Feb-24 Mar-24 Apr-24 May-24 Jun-24 Jul-24 Aug-24
1 | 100 | 120 | 130 | 140 | 150 | 160 | 170 | 180 | 190 | 200 | 210 | 220 |
2 | 90 | 110 | 120 | 130 | 140 | 150 | 160 | 170 | 180 | 190 | 200 | 210 |
You should transform it into:
ID Month Value
1 | Sep-23 | 100 |
1 | Oct-23 | 120 |
1 | Nov-23 | 130 |
1 | Dec-23 | 140 |
1 | Jan-24 | 150 |
1 | Feb-24 | 160 |
1 | Mar-24 | 170 |
1 | Apr-24 | 180 |
1 | May-24 | 190 |
1 | Jun-24 | 200 |
1 | Jul-24 | 210 |
1 | Aug-24 | 220 |
2 | Sep-23 | 90 |
2 | Oct-23 | 110 |
2 | Nov-23 | 120 |
2 | Dec-23 | 130 |
2 | Jan-24 | 140 |
2 | Feb-24 | 150 |
2 | Mar-24 | 160 |
2 | Apr-24 | 170 |
2 | May-24 | 180 |
2 | Jun-24 | 190 |
2 | Jul-24 | 200 |
2 | Aug-24 | 210 |
You can do this transformation in Power Query Editor.
Create a Date Parameter: Create a parameter that dynamically holds the latest month you want to include in your table visual. You can do this by going to the "Modeling" tab in Power BI Desktop and selecting "New Parameter." Set the data type to Date/Time and specify the allowed values based on your date columns.
Create a Measure: Create a measure that calculates the sum of the values for the selected months. The measure might look like this:
TotalValue =
VAR SelectedMonth = MAX('DateParameter'[Value])
RETURN
CALCULATE(SUM(YourTable[Value]), YourTable[Month] <= SelectedMonth)
Replace 'DateParameter' and 'YourTable' with the appropriate names from your model.
Create a Table Visual: Finally, create a table visual with the 'Month' column and the 'TotalValue' measure. You can use a slicer or a parameter to dynamically change the selected month, and the 'TotalValue' measure will adjust accordingly to sum the data for the selected months.
Now, when you change the parameter or slicer value to a specific month, the table visual will automatically adjust to display the data for that month and sum the values accordingly. Columns for future months will be automatically added as your data updates, and the old columns will be removed.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
134 | |
91 | |
89 | |
64 | |
58 |
User | Count |
---|---|
201 | |
137 | |
107 | |
72 | |
68 |