Building a matrix with columns == days of month when recordset cannot return all days of month - dynamics-crm-online

I'm trying to put together an attendance report for a school that tracks student attendance codes for that student for every day on the calendar month in a DynamicsCRM system being used as a managed service (that is to say, I build queries using FetchXML and cannot use SQL). The format for the report requires that a column for every day in the month be listed for the report. My student table that tracks this attendance however only contains records for days where an attendance value is recorded, and I do not have an object available that can return every day in a month for me.
I am looking for a solution other than hardcoding 31 columns and using conditionals to control the display of the last three day columns. Ideally, I'd like a conditional in my matrix column grouping that would look at the date value for the previously generated column and determine if the next date record from my resultset is sequentially the next day of that month, and if not, create the next sequential date, move to the next column and perform the check again until it is true. Is there a way I can do this, or another means to accomplish my goal that does not involve hard-coding day columns into a table or matrix? Right now, I have nothing; I can barely imagine how I think this should look.

What I did to solve the same issue has been to create a scheduled process each day to create a record and deactivate it.
I have then been able to distinguish actual records (the active ones) from these 'placeholders' (inactive ones) in my querying.

Related

How can I filter a table for the field values on the last(highest) date in a custom four week period, using DAX in Power BI?

I created a calculated table based on start and end dates to check which manager is responsible for a product per date.
Result:
The financial department uses a four week period to report. So 13 periods per year.
(not usable in a date table?)
Product number 8098 gets a different manager on the 23rd of januari this year.
So at the start manager C5104 is responsible and at the end of period one (202301) C5107 is responsible.
To get one responsible manager per period I'd like to filter the table in such a fashion that I get the numbers from the last date in a period. After filtering I don't need the [date] field anymore.
I hope I'm just missing something basic like the 'ELLEXCEPT' But I'm lost...
DISTINCT gives:
One row too many. I'd like to lose the row: 8098, C5104, 202301.
To keep only rows showing the manager per product at the end of a period.

Custom function by date for related tables

"In a crosstab, latest month where Actuals has any data, show Actuals data for that and all previous months. Future months, show Forecast data."
.
I have two tables- Forecasts and Actuals- and the common columns between them are Team, Month, Value.
I'd like to show the data in a crosstab with Month as columns and Team as rows. I'm trying to write an expression to do this in the crosstab: The most recent month where Actuals has any data, I'd like to show Actuals data for that and all previous months, for all teams. For following months, I'd like to show Forecast data.
Any suggestions about how to go about this would be appreciated. I'm still piecing together my knowledge :)
Create a third table from a transformations:
Create Third table from - Pivot date on Team & Month (to ensure every possible combination) from first table
Add Rows from transforming the second table (pivot on Team & Month)
Join the two original tables to your newly created table (has every possible combination of Team & Month) so that both your data sets are now in one table.
Now use the third table in your cross table.
If you try using column matching instead of the above method only dates from the main table will show as the dates are matched and ones missing from the other will not display.

Track the rows which were updated or encrypted

I want to scrub(or encrypt) the email information from a few tables which are older than a few years.
This I am planning to do as part of a job, next time when I run the job how can I omit the rows which are already scrubbed or encrypted.
I am looking for an approach which will be having good performance.
"I want to scrub(or encrypt) the email information from a few tables which are older than a few years"
I hope this means you have a date column on these tables which you can use to determine which ones need to be scrubbed. The most efficient way of tackling the job is to track that date in an operational table, recording the most recent date scrubbed.
For example you have ten years' worth of data, and you need to scrub records which are more than four years old. Now this would work:
update t23
set email = null
where date_created < add_months(sysdate, -48);
But it seems like you want to batch things up. So build a tracking table, which at its simplest would be
create table tracker (
last_date_scrubbed);
Populate the last_date_scrubbed with a really old date say date '2010-01-01'
Now you can write a query like this
update t23
set email = null
where date_created
< (select last_date_scrubbed + interval '1' year from tracker);
That will clean all records older than 2011. Increment the date in the tracker table by one year. Run the query again to clean stuff from 2011. Repeat until you get to your target state of cleanliness. At which point you can switch to running the query monthly , with an interval of one month , or whatever.
Obviously you should proceduralize this. A procedure is the best way to encapsulate the steps and make sure everything is kept in step. Also you can use the database scheduler to run the procedure.
"there is one downside to this approach. I thought that you want to be free upon choosing which rows to be updated."
I don't see any requirement to track which individual rows have been scrubbed. After all, the end state is that every record older than a certain date has been scrubbed. When I have done jobs like this previously all anybody wanted to know was, "how many rows have we done so far and how many have we still got to do?" Which can be answered by tracking the sql%rowcount for each run.
For The best performance, you can add a Flag Column to your main table. a Column like IsEncrypted. then every time you try to run any query for the "not Encrypted rows" you easily use WHERE when IsEncrypted Column is false to condition on those rows only. there are other ways though.
EDIT
another way is to create a logger table. basically what this table does, is that it records any more information you want about a certain ID in another table. have another table called EncryptionLogger, in it you would have at least two columns: EmailTableId, IsEncrypted. then in any query you can simply get any rows WHERE their Ids are NOT IN this table.

Can I generate the number of business days in a month in Visual Studio?

I have a report that takes sales data from a few tables. I want to add a field that will divide the total sales for the given month by the total number of business days in that same month. Is there a way I can calculate that in an expression? Do I need to create a new table in the database specifically for months and their number of business days? How should I go about this?
Thank you
Intuitively, I would say that you need a simple function and a table.
The table is to host the exceptions like Independence day, labor day, etc.
The function will get two parameters: Month and Year (I'm not providing any sample code since you haven't specified which language you are using).
It will then build a date as yyyy-mm-01 (meaning, first day of the month). If will then loop from 2 to 31 and:
Create a new date by adding the index of the loop to the initial date,
Check if the resulting date is still within the month,
Check if it is a working or not working day (e.g. Sunday),
Check if it is found within the table of exceptions.
If the created date passes all the above tests, you add 1 to the counter.
Though it might look complex, it is not and it will provide you the correct answer regardless of the month (e.g. Feb.) and the year (leap or not).

SSRS Matrix Bespoke Headers (Still from datasource!!)

I have to create a matrix in SSRS to detail the number uses leaving an organisation.
The columns will all represent spaces of time spanning 1 week and the rows will all represent departements in the organisation. The detail portion will be a count of people who have left that area in that week.
I have a leaving date field in the DB but nothing that flags the specific intevals I have been told to use. That means that as the matrix is, it counts each of users that have left a specific department however the date range columns is 1 day, not 1 week. Is there a way to force the column headers to respect the week intervals I want given that they are currently coming from the dataset and are not hard coded?
Firstly try to manage your data in sql itself by using Group By with date and making each group as one week period. That way you can manage to get all data in your required format
I don't know what is your columns so I am just showing a way to get the week groups from table and get the count of the people
SELECT DATEPART(wk, datevaluecolumn) weekno
, SUM(peopleleavingcolumn) totalvalue
FROM yourTable
GROUP BY DATEPART(wk, datevalue)

Resources