Forum Discussion
Slicer selection not working in virtual table creation
- Anonymous1 year ago
Hi GalaBI79 ,
I made a sample for you.
Measure = var _column = MAX('Table3'[Column1]) var _value= SWITCH(TRUE(), _column="Today"&&HASONEVALUE('Calendar'[Date]),CALCULATE([InvoiceValue],'Invoice'[InvoiceDate]=SELECTEDVALUE('Calendar'[Date])), _column="Month"&&HASONEVALUE('Calendar'[Date]),CALCULATE([InvoiceValue],FORMAT('Invoice'[InvoiceDate],"MMMM")=SELECTEDVALUE('Calendar'[Date].[Month])), _column="Month To Date"&&HASONEVALUE('Calendar'[Date]),CALCULATE([InvoiceValue],Month('Invoice'[InvoiceDate])<=MONTH(SELECTEDVALUE('Calendar'[Date]))), _column="Today"&&HASONEVALUE('Calendar'[Date].[Month]),CALCULATE([InvoiceValue],'Invoice'[InvoiceDate]=MAX('Calendar'[Date])), _column="Month"&&HASONEVALUE('Calendar'[Date].[Month]),CALCULATE([InvoiceValue],FORMAT('Invoice'[InvoiceDate],"MMMM")=SELECTEDVALUE('Calendar'[Date].[Month])), _column="Month To Date"&&HASONEVALUE('Calendar'[Date].[Month]),CALCULATE([InvoiceValue],Month('Invoice'[InvoiceDate])<=MONTH(MIN('Calendar'[Date]))) ) RETURN _valueNote: This measure only considers the month and does not consider the year as a filter condition.
Best Regards,
Wearsky
Hi GalaBI79 ,
Please share the sample data and the expected outputs.
If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Best Regards,
Wearsky
Hi Anonymous and thanks for the reply,
here is an example of the main table. For privacy reasons I had to remove some columns, the ones in the example are the ones I use in the formulas.
| InvoiceNumber | InvoiceDate | Type | Brand |
| 108230 | 29/07/2024 | WL | T |
| 405405 | 29/07/2024 | WL | T |
| 457698 | 29/07/2024 | WL | T |
| 331583 | 29/07/2024 | WL | T |
| 497201 | 29/07/2024 | WL | T |
| 469280 | 29/07/2024 | WL | T |
| 13797 | 29/07/2024 | WL | T |
| 282243 | 29/07/2024 | WL | T |
| 268638 | 29/07/2024 | WL | T |
Below is an example of the "Calendar" table, which I use to manage filters in slicers:
| DATE | DAY_LABEL_ITA | DAY_LABEL_ENG | DAY | MONTH_LABEL_ITA | MONTH_LABEL | MONTH | YEAR | WORK_DAYS | WEEKEND |
| 01/01/2023 | Domenica | Sunday | 01 | Gennaio | January | 01 | 2023 | 0 | 1 |
| 02/01/2023 | Lunedi | Monday | 02 | Gennaio | January | 01 | 2023 | 1 | 0 |
| 03/01/2023 | Martedì | Tuesday | 03 | Gennaio | January | 01 | 2023 | 1 | 0 |
| 04/01/2023 | Mercoledì | Wednesday | 04 | Gennaio | January | 01 | 2023 | 1 | 0 |
| 05/01/2023 | Giovedi | Thursday | 05 | Gennaio | January | 01 | 2023 | 1 | 0 |
| 06/01/2023 | Venerdì | Friday | 06 | Gennaio | January | 01 | 2023 | 0 | 0 |
| 07/01/2023 | Sabato | Saturday | 07 | Gennaio | January | 01 | 2023 | 0 | 1 |
| 08/01/2023 | Domenica | Sunday | 08 | Gennaio | January | 01 | 2023 | 0 | 1 |
| 09/01/2023 | Lunedi | Monday | 09 | Gennaio | January | 01 | 2023 | 1 | 0 |
The main table and the Calendar table are connected by "Many to one" relationship and "Single" direction. I also tried with "Both" but nothing changed.
These are the expected results. All three rows should vary depending on the filters YEAR, MONTH and DAY.
Ex. if I select 31/07/2024, I should see:
- Today: data from 31/07/2024;
- Month: data from the month of July;
- Month to date: data from January to July.
If I select only the month and not the single day, I should see the maximum date for the selected month.
If I create 3 separate custom tables and put the data in one table, everything works. If I create a custom table in union from these tables, I lose all the filters.
Best regards,
Nicola