Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hi everyone,
I have a typical date table and another table with the column "Year", another one "Quantity" and a last one called "Sales".
I need to create a matrix visual where the rows you can see in the image below: The month-year selected in a slicer, the data of all past year (Not only december but I can't call it anything else than that), the data of 2 years ago, etc.
I have been able to create a measure that can display it correctly, but measures can't be used as rows in these visuals, so it has to be a column.
The measure I created is
Previous_Years =
var id_year_SALES = SELECTEDVALUE(SalesTable[ID_YEAR])
var id_year_DATE = SELECTEDVALUE(DIM_CALENDAR[NUM_YEAR])
RETURN
SWITCH(id_year_DATE - id_year_SALES,
0, FORMAT(SELECTEDVALUE(DIM_CALENDAR[DATE]), "MMMM YY"),
1, CONCATENATE("DECEMBER ", id_year_DATE - 1),
2, CONCATENATE("DECEMBER ", id_year_DATE - 2),
3, CONCATENATE("DECEMBER ", id_year_DATE - 3),
"Error")I didn't even try the part with "Difference with Dec. Previous Year".
If you need any more detail or explanation feel free to ask.
Thank you!
Solved! Go to Solution.
@DevLearner0 , Create a date table if you do not have
DateTable =
ADDCOLUMNS (
CALENDAR (DATE (2000, 1, 1), DATE (2030, 12, 31)),
"Year", YEAR ( [Date] ),
"Month", MONTH ( [Date] ),
"MonthYear", FORMAT ( [Date], "MMM YYYY" )
)
Add calculated columns to your SalesTable to represent the different periods. Here’s how you can do it:
CurrentYear = YEAR(TODAY())
MonthYear = FORMAT(SalesTable[Date], "MMM YYYY")
PreviousYear =
IF (
SalesTable[Year] = CurrentYear - 1,
"DECEMBER " & (CurrentYear - 1),
BLANK()
)
TwoYearsAgo =
IF (
SalesTable[Year] = CurrentYear - 2,
"DECEMBER " & (CurrentYear - 2),
BLANK()
)
ThreeYearsAgo =
IF (
SalesTable[Year] = CurrentYear - 3,
"DECEMBER " & (CurrentYear - 3),
BLANK()
)
Proud to be a Super User! |
|
@DevLearner0 , Create a date table if you do not have
DateTable =
ADDCOLUMNS (
CALENDAR (DATE (2000, 1, 1), DATE (2030, 12, 31)),
"Year", YEAR ( [Date] ),
"Month", MONTH ( [Date] ),
"MonthYear", FORMAT ( [Date], "MMM YYYY" )
)
Add calculated columns to your SalesTable to represent the different periods. Here’s how you can do it:
CurrentYear = YEAR(TODAY())
MonthYear = FORMAT(SalesTable[Date], "MMM YYYY")
PreviousYear =
IF (
SalesTable[Year] = CurrentYear - 1,
"DECEMBER " & (CurrentYear - 1),
BLANK()
)
TwoYearsAgo =
IF (
SalesTable[Year] = CurrentYear - 2,
"DECEMBER " & (CurrentYear - 2),
BLANK()
)
ThreeYearsAgo =
IF (
SalesTable[Year] = CurrentYear - 3,
"DECEMBER " & (CurrentYear - 3),
BLANK()
)
Proud to be a Super User! |
|
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 44 | |
| 43 | |
| 38 | |
| 18 | |
| 16 |
| User | Count |
|---|---|
| 67 | |
| 63 | |
| 30 | |
| 30 | |
| 23 |