Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Get particular text from the cell with M code

Hi,

 

I would like to get only week number e.g. '11' from Source name. 

Please help for M code.

 

 

 

  • Hi Anonymous - you can achieve this in two ways in M code add a new custom column as bleow

    Text.Middle([Source Name],1,2)

     

     

    Method2: Text.BetweenDelimiters([Source Name], "W", "_")

    column from example with selection of source name column , you can give suggestion of 1 example to the query engine , you can achieve the output as expected.

     

     

     

    Hope it works

     

2 Replies

  • Hi Anonymous - you can achieve this in two ways in M code add a new custom column as bleow

    Text.Middle([Source Name],1,2)

     

     

    Method2: Text.BetweenDelimiters([Source Name], "W", "_")

    column from example with selection of source name column , you can give suggestion of 1 example to the query engine , you can achieve the output as expected.

     

     

     

    Hope it works

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks it works, accepted.

      Another question pls, can we add Minus function with today's week number?

      e.g. 30(from W30 xxxxxx(source.name)) - 35(from today's week) which result will be -5

       

      I wanna get data only in the last 26 weeks(half year) but the numbers from custom column you helped doens't have filter for this function, it seems only date filter is available. 

       

      So I wanna make calculation to filter if it is below than -26 than unfilter.