This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
Buongiorno a tutti,
sono nuovo del forum e approfitto per salutare tutti i membri.
Come da oggetto ho un problema con un mio report di PowerBI nel quale sto tentando di applicare un filtro Like4Like (si/no).
Vi spiego nel dettaglio il (anzi i miei) problemi:
Ho una tabella denominata Calendario con al suo interno una colonna denominata Data con tutte le date che utilizzo per apporre filtri temporali in tutte le pagine del report.
Ho un'altra tabella che importo da un database SQL Server denominata V_ANAGNEG dove al suo interno ci sono le informazioni dettagliate dei negozi che analizzo nelle varie pagine del report. All'interno di questa tabella sono presenti due colonne DataApertura (che corrisponde alla data della prima vendita e
ffettuata dal negozio) e DataChiusura (che corrisponde alla data di chiusura definitiva al pubblico del negozio).
Ho una tabella che importo da un database SQL Server denominata VENSCO (che è la mia tabella dei fatti) dove al suo interno ci sono le informazioni delle vendite giornaliere per singolo negozio.
Le tre tabelle sono tra loro così collegate:
- Calendario[Data] -> VENSCO[DataScontrino]
- V_ANAGNEG[CodNeg] -> VENSCO[Negozio]
La colonna che utilizzo per il calcolo del fatturato è VENSCO[TotaleSco] con la seguenti misure
- IncassoAC= SUM(VENSCO[TotaleSco]) che mi serve per filtrare l'incasso dell'anno/mese/giorno selezionato
- IncassoAP = CALCULATE([IncassoAC], SAMEPERIODLASTYEAR(Calendario[Data])) che mi serve per visualizzare l'incasso dell'anno precedente in base al filtro anno/mese/giorno applicato.
Quello che vorrei realizzare è un filtro visivo denominato Like4Like -> (Si/No) che quando seleziono "Si" mi faccia visualizzare solo i negozi che (in base al periodo data selezionato) era aperti lo scorso anno con relativo confronto del fatturato del periodo selezionate e del pari fatturato dell'anno precedente.
Viceversa se seleziono "No" il filtro mi deve far visualizzare solo i negozi che non sono confrontabili o perchè non erano aperti lo scorso anno oppure sono stati chiusi definitivamente.
Ovviamente se tolgo entrambi i filtri (Si/No) devo poter visualizzare tutti i negozi a prescindere dal confronto.
Vi riporto un esempio che replicherò in excel (che allego):
Il negozio 100 è stato aperto per la prima volta al pubblico il 25/07/2024. Fino al 25/07/2025 entra tra i negozi Like4Like = No e dunque il suo fatturato non è confrontabile. A partire dal 25/07/2025 il negozio entra tra i negozi Like4Like = Si e dunque a partire da quella data il suo fatturato sarà confrontabile con quello dell'anno precedente.
| Filtro Like4Like =Si | |||||
| CodNeg | Anno | Mese | Giorno | IncassoAC | IncassoAP |
| 100 | 2025 | Luglio | 1 | ||
| 100 | 2025 | Luglio | 2 | ||
| 100 | 2025 | Luglio | 3 | ||
| 100 | 2025 | Luglio | 4 | ||
| 100 | 2025 | Luglio | 5 | ||
| 100 | 2025 | Luglio | 6 | ||
| 100 | 2025 | Luglio | 7 | ||
| 100 | 2025 | Luglio | 8 | ||
| 100 | 2025 | Luglio | 9 | ||
| 100 | 2025 | Luglio | 10 | ||
| 100 | 2025 | Luglio | 11 | ||
| 100 | 2025 | Luglio | 12 | ||
| 100 | 2025 | Luglio | 13 | ||
| 100 | 2025 | Luglio | 14 | ||
| 100 | 2025 | Luglio | 15 | ||
| 100 | 2025 | Luglio | 16 | ||
| 100 | 2025 | Luglio | 17 | ||
| 100 | 2025 | Luglio | 18 | ||
| 100 | 2025 | Luglio | 19 | ||
| 100 | 2025 | Luglio | 20 | ||
| 100 | 2025 | Luglio | 21 | ||
| 100 | 2025 | Luglio | 22 | ||
| 100 | 2025 | Luglio | 23 | ||
| 100 | 2025 | Luglio | 24 | ||
| 100 | 2025 | Luglio | 25 | 6.403,29 | 9.595,81 |
| 100 | 2025 | Luglio | 26 | 7.365,76 | 7.238,61 |
| 100 | 2025 | Luglio | 27 | 4.536,60 | 12.078,43 |
| 100 | 2025 | Luglio | 28 | 4.829,87 | 7.726,98 |
| 100 | 2025 | Luglio | 29 | 4.684,53 | 8.545,81 |
| 100 | 2025 | Luglio | 30 | 4.387,62 | 7.202,50 |
| 100 | 2025 | Luglio | 31 | 4.035,32 | 6.751,65 |
| Total | 36.242,99 | 59.139,79 |
| Filtro Like4Like =No | |||||
| CodNeg | Anno | Mese | Giorno | IncassoAC | IncassoAP |
| 100 | 2025 | Luglio | 1 | 3.864,85 | |
| 100 | 2025 | Luglio | 2 | 3.487,34 | |
| 100 | 2025 | Luglio | 3 | 3.477,40 | |
| 100 | 2025 | Luglio | 4 | 4.427,06 | |
| 100 | 2025 | Luglio | 5 | 5.381,44 | |
| 100 | 2025 | Luglio | 6 | 4.343,75 | |
| 100 | 2025 | Luglio | 7 | 4.146,23 | |
| 100 | 2025 | Luglio | 8 | 4.396,50 | |
| 100 | 2025 | Luglio | 9 | 3.756,53 | |
| 100 | 2025 | Luglio | 10 | 3.644,70 | |
| 100 | 2025 | Luglio | 11 | 4.473,52 | |
| 100 | 2025 | Luglio | 12 | 5.615,18 | |
| 100 | 2025 | Luglio | 13 | 3.794,03 | |
| 100 | 2025 | Luglio | 14 | 3.792,58 | |
| 100 | 2025 | Luglio | 15 | 4.458,14 | |
| 100 | 2025 | Luglio | 16 | 4.048,80 | |
| 100 | 2025 | Luglio | 17 | 3.974,55 | |
| 100 | 2025 | Luglio | 18 | 4.726,88 | |
| 100 | 2025 | Luglio | 19 | 5.644,77 | |
| 100 | 2025 | Luglio | 20 | 4.249,93 | |
| 100 | 2025 | Luglio | 21 | 4.554,72 | |
| 100 | 2025 | Luglio | 22 | 3.991,74 | |
| 100 | 2025 | Luglio | 23 | 4.052,78 | |
| 100 | 2025 | Luglio | 24 | 3.727,07 | |
| 100 | 2025 | Luglio | 25 | ||
| 100 | 2025 | Luglio | 26 | ||
| 100 | 2025 | Luglio | 27 | ||
| 100 | 2025 | Luglio | 28 | ||
| 100 | 2025 | Luglio | 29 | ||
| 100 | 2025 | Luglio | 30 | ||
| 100 | 2025 | Luglio | 31 | ||
| Total | 102.030,48 | - |
Ho cercato sia nel forum, ho Goglato per diverso tempo ma una soluzione adattabile alla mia necessità non l'ho trovata.
Capisco che il posto è molto lungo ma ho cercato di darvi il maggior numero di informazioni per consentirvi di aiutarmi
Grazie Antonello
Solved! Go to Solution.
Hi @AntonelloLucia,
I found a first solution creating a disconnected table and injecting your selection into the DAX code
Does that work? I have to optimize it but can you confirm it is working correctly?
Thanks
If this helped, please consider giving kudos and mark as a solution
@me in replies or I'll lose your thread
Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
Thank you for submitting your question to the Microsoft Fabric Community Forum, and thanks to @Bmejia , @ABD128 and @FBergamaschi for offering helpful suggestions.
Could you let us know if the suggested solution resolved your issue?If you still need help, please share more details so we can assist you further.
Thank you.
I am not sure if this will help. Update this measurement with this additional, so it filters out the data from today.
just a note that when you are using TotalYTD it is calculating from the begining of year. I notice you might be using a manual calendar that you might be updating from your desktop and your first weeks starts in December to match the exact day of the week. If that is working for you should be fine just making note that you might end up with wrong values.
Hey @AntonelloLucia
Instead of a column in VENSCO, you should define measures that dynamically test store open/close dates for both the current date and the same date last year.
1. Like4Like Flag
Determines if a store/date is comparable (open now and open same day last year).
Like4Like Flag :=
VAR d = SELECTEDVALUE ( 'Calendario'[Data] )
VAR dLY =
CALCULATE ( MIN ( 'Calendario'[Data] ), SAMEPERIODLASTYEAR ( 'Calendario'[Data] ) )
VAR openDate = SELECTEDVALUE ( V_ANAGNEG[Opening Date] )
VAR closeDate = COALESCE ( SELECTEDVALUE ( V_ANAGNEG[Closing Date] ), DATE (2099,12,31) )
VAR IsOpenNow =
NOT ISBLANK(d) &&
d >= openDate &&
d <= closeDate
VAR IsOpenLY =
NOT ISBLANK(dLY) &&
dLY >= openDate &&
dLY <= closeDate
RETURN
SWITCH (
TRUE(),
IsOpenNow && IsOpenLY, "Yes",
"No"
)
2. IncassoAC (L4L)
Current year revenue, only when Like4Like = Yes.
IncassoAC (L4L) :=
IF ( [Like4Like Flag] = "Yes", [IncassoAC] )
3. IncassoAP (L4L)
Previous year revenue, only when Like4Like = Yes.
IncassoAP (L4L) :=
IF ( [Like4Like Flag] = "Yes", [IncassoAP] )
Use Like4Like Flag as a filter (Yes/No) Or directly use IncassoAC (L4L) and IncassoAP (L4L) in visuals for the “Yes” case
Regards,
ABD.
Ho @ABD128
Thanks for the support but I need to have a Visual Filter Like4Like (Yes/No). If I use your code I won't be able to insert it in a visual filter. I would also prefer to have the calculated IncassoAC and IncassoAP fields for example that are modified based on the Like4Like visual filter so as to avoid confusion for the user in reading the data and above all not to add too many fields in the report visualisation.
Implementing a daily Like4Like filter that adapts to store opening and closing dates, while providing end user control via a slicer, presents a complex challenge. Standard Power BI time intelligence and filtering capabilities are not inherently suited for daily-level “store lifecycle” logic, especially when combined with Like4Like comparisons. While it is possible to address this with DAX measures and conditional logic, managing report simplicity, supporting current and prior periods, and enabling a single visual filter with Yes/No/All options adds significant complexity. For scenarios that require customized data modeling, advanced DAX solutions, and adherence to specific business rules for Like4Like analysis, it is advisable to consult with a Power BI solution partner. These experts can review your data model, confirm your business requirements, and assist in building a scalable solution. Microsoft provides a directory of certified Power BI partners specializing in advanced modeling and custom DAX development, available here: Power Bi Partners
Regards,
ABD
Ciao,
Da quello che ho capito, potresti aver bisogno di aggiungere una misura di colonna nella tabella VENSCO simile a questa. Se il tuo elemento visivo contiene il data scontrino, potrebbe essere necessario modificarlo con la data del calendario e creare un filtro basato sulla data del calendario.
|
Like4Like =
VAR negozio_chiuso =
CALCULATE (
SELECTEDVALUE ( V_ANAGNEG[Data Chiusa] ),
ALLEXCEPT ( V_ANAGNEG, V_ANAGNEG[CodNeg] )
) -- se più di un valore potrebbe essere Min o Max invece di SelectedValue
VAR negozio_aperto =
CALCULATE (
SELECTEDVALUE ( V_ANAGNEG[ Data Aperta] ),
ALLEXCEPT ( V_ANAGNEG, V_ANAGNEG[CodNeg] )
) ---se più di un valore potrebbe essere Min o Max invece di SelectedValu
RETURN
SWITCH (
TRUE (),
VENSCO[DataScontrino] <= negozio_chiuso
&& VENSCO[DataScontrino] >= negozio_aperto, "Si",
ISBLANK ( negozio_chiuso ), "Si",
"No"
)
|
Ciao Antonello,
riesci ad allegare i tuoi dati completi? Puoi mettere un pbix in un googledrive and postarmi qui il link os pedirlo via messaggio privato. Così ti sistemo tutto. Grazie
F
PS ottimo post, servono dettagli o non si riesce a dare supporto per bene
Buon pomeriggio e buona domenica a tutti,
ti riporto di seguito il link al report di PBI.
Ho provato anche a creare la colonna come suggerito da @Bmejia ma non va comunque.
@FBergamaschi, ho inserito due casi specifici il primo (3222-Poggibonsi) che ha chiuso il 31/03/2025 non sarebbe più in like4like da tale data; il secondo caso (3124-Canicattì) ha aperto al pubblico il 25/07/2024 e deve andare in like4like a partire dal 25/07/2025.
Capisco che a livello di dottrina like4like "ragiona" per week intere o mesi interi ma nella mia azienda l'area commerciale vuole un like4like giornaliero che però tenga conto della Data di apertura al pubblico e della Data di chiusua al pubblico (ovviamente chiusure di un giorno, due o al massimo di una settimana non vengono prese in cosiderazione in questo confronto).
Mi scusa ancora se sono ripetitivo o prolisso (deformazione professionale 😅) ma cerco di fornire il maggior numero di dettagli al fine di consentire agli altri di lavorare meglio e al meglio.
Grazie per quanto andrete a fare.
Un caro saluto
https://1drv.ms/u/c/4bf2ac14125027ba/ERbY3MS1AAdKposGN3XDV8oBWcmcosLUBJJfAsymPnpshw
Hi @AntonelloLucia,
I found a first solution creating a disconnected table and injecting your selection into the DAX code
Does that work? I have to optimize it but can you confirm it is working correctly?
Thanks
If this helped, please consider giving kudos and mark as a solution
@me in replies or I'll lose your thread
Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
Hi @FBergamaschi,
That's exactly what I was looking for. Thank you for your availability and professionalism.
best regards
Thanks to you. I just noticed this is not the DAX section, would you mind repost your original post in that section so we link it to this solution?
Thanks
If this helped, please consider giving kudos and mark as a solution
@me in replies or I'll lose your thread
Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 31 | |
| 23 | |
| 23 | |
| 19 | |
| 16 |
| User | Count |
|---|---|
| 63 | |
| 36 | |
| 28 | |
| 23 | |
| 22 |