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
Ivancito111
Resolver I
Resolver I

Occupy a variable with a table name

Hello, good afternoon, I am writing to you because I have a question about a table filter.
What happens is that I have a value that changes by month and day, ie, today we are in September 20, I need to display the value with these two filters.

 

DiaEneroFebreroMarzoAbrilMayoJunioJulioAgostoSeptiembre

12222333336444495555126666157777188888219999251110
22222333336444495555126666157777188888219999251110
32222333336444495555126666157777188888219999251110
42222333336444495555126666157777188888219999251110
52222333336444495555126666157777188888219999251110
62222333336444495555126666157777188888219999251110
72222333336444495555126666157777188888219999251110
82222333336444495555126666157777188888219999251110
92222333336444495555126666157777188888219999251110
102222333336444495555126666157777188888219999251110
112222333336444495555126666157777188888219999251110
122222333336444495555126666157777188888219999251110
132222333336444495555126666157777188888219999251110
142222333336444495555126666157777188888219999251110
152222333336444495555126666157777188888219999251110
162222333336444495555126666157777188888219999251110
172222333336444495555126666157777188888219999251110
182222333336444495555126666157777188888219999251110
192222333336444495555126666157777188888219999251110
202222333336444495555126666157777188888219999251110
212222333336444495555126666157777188888219999251110
222222333336444495555126666157777188888219999251110
232222333336444495555126666157777188888219999251110
242222333336444495555126666157777188888219999251110
252222333336444495555126666157777188888219999251110
262222333336444495555126666157777188888219999251110
272222333336444495555126666157777188888219999251110
282222333336444495555126666157777188888219999251110
292222333336444495555126666157777188888219999251110
302222333336444495555126666157777188888219999251110
31  64444 126666157777 219999 

 

and so on with all the months and days of the month.

In what I have researched I managed to filter by day (today's 20th), but I still can't do it by month.

Ivancito111_0-1632146697589.png

I remain attentive to any comments that allow me to do so.

1 ACCEPTED SOLUTION

@Ivancito111 The only thing you are left with is a big long SWITCH statement like:

 

 

Measure = 
  VAR __dia = DAY(TODAY())
  VAR __month = MONTH(TODAY())
RETURN
  SWITCH(__month),
    1, CALCULATE(SUMX('Tabla1', 'Tabla1'[Enero]), FILTER('Tabla1','Tabla1'[Dia]=__dia)),
    2, CALCULATE(SUMX('Tabla1', 'Tabla1'[Febrero]), FILTER('Tabla1','Tabla1'[Dia]=__dia)),
    3, CALCULATE(SUMX('Tabla1', 'Tabla1'[Marzo]), FILTER('Tabla1','Tabla1'[Dia]=__dia)),
    ...
  )
    

 

Also, the unpivoting would be in Power Query Editor, not in the source data.

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

@Ivancito111 You would likely have better luck if you unpivoted your month columns in Power Query.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

But I still have the problem that it must choose the column depending on the month in which we are.

@Ivancito111 If you unpivot the columns then no, you are simply filtering rows at that point. This is why it works better than having rows spread out across the table. If you unpivot then you should have:

Dia, Attribute, Value

1, Enero, 111

1, Februaro, 1111

 

So, all you have to do is filter Attribute for the month you want. No column selection needed, it is always Attribute.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I know that your answer solves my problem, but isn't there a method that doesn't ruin my board?

@Ivancito111 The only thing you are left with is a big long SWITCH statement like:

 

 

Measure = 
  VAR __dia = DAY(TODAY())
  VAR __month = MONTH(TODAY())
RETURN
  SWITCH(__month),
    1, CALCULATE(SUMX('Tabla1', 'Tabla1'[Enero]), FILTER('Tabla1','Tabla1'[Dia]=__dia)),
    2, CALCULATE(SUMX('Tabla1', 'Tabla1'[Febrero]), FILTER('Tabla1','Tabla1'[Dia]=__dia)),
    3, CALCULATE(SUMX('Tabla1', 'Tabla1'[Marzo]), FILTER('Tabla1','Tabla1'[Dia]=__dia)),
    ...
  )
    

 

Also, the unpivoting would be in Power Query Editor, not in the source data.

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.

Top Solution Authors